Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename via_hub to via_device #24360

Merged
merged 2 commits into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/config/device_registry.py
Expand Up @@ -69,7 +69,7 @@ def _entry_dict(entry):
'name': entry.name,
'sw_version': entry.sw_version,
'id': entry.id,
'hub_device_id': entry.hub_device_id,
'via_device_id': entry.via_device_id,
'area_id': entry.area_id,
'name_by_user': entry.name_by_user,
}
2 changes: 1 addition & 1 deletion homeassistant/components/deconz/deconz_device.py
Expand Up @@ -72,5 +72,5 @@ def device_info(self):
'model': self._device.modelid,
'name': self._device.name,
'sw_version': self._device.swversion,
'via_hub': (DECONZ_DOMAIN, bridgeid),
'via_device': (DECONZ_DOMAIN, bridgeid),
}
7 changes: 4 additions & 3 deletions homeassistant/components/homekit_controller/__init__.py
Expand Up @@ -156,11 +156,12 @@ def device_info(self):
'sw_version': self._accessory_info.get('firmware.revision', ''),
}

# Some devices only have a single accessory - we don't add a via_hub
# otherwise it would be self referential.
# Some devices only have a single accessory - we don't add a
# via_device otherwise it would be self referential.
bridge_serial = self._accessory.connection_info['serial-number']
if accessory_serial != bridge_serial:
device_info['via_hub'] = (DOMAIN, 'serial-number', bridge_serial)
device_info['via_device'] = (
DOMAIN, 'serial-number', bridge_serial)

return device_info

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/homematicip_cloud/device.py
Expand Up @@ -45,7 +45,8 @@ def device_info(self):
'manufacturer': self._device.oem,
'model': self._device.modelType,
'sw_version': self._device.firmwareVersion,
'via_hub': (homematicip_cloud.DOMAIN, self._device.homeId),
'via_device': (
homematicip_cloud.DOMAIN, self._device.homeId),
}
return None

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hue/light.py
Expand Up @@ -334,7 +334,7 @@ def device_info(self):
'model': self.light.productname or self.light.modelid,
# Not yet exposed as properties in aiohue
'sw_version': self.light.raw['swversion'],
'via_hub': (hue.DOMAIN, self.bridge.api.config.bridgeid),
'via_device': (hue.DOMAIN, self.bridge.api.config.bridgeid),
}

async def async_turn_on(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hue/sensor_base.py
Expand Up @@ -269,7 +269,7 @@ def device_info(self):
self.primary_sensor.productname or
self.primary_sensor.modelid),
'sw_version': self.primary_sensor.swversion,
'via_hub': (hue.DOMAIN, self.bridge.api.config.bridgeid),
'via_device': (hue.DOMAIN, self.bridge.api.config.bridgeid),
}


Expand Down
32 changes: 18 additions & 14 deletions homeassistant/components/mqtt/__init__.py
Expand Up @@ -79,7 +79,8 @@
CONF_MANUFACTURER = 'manufacturer'
CONF_MODEL = 'model'
CONF_SW_VERSION = 'sw_version'
CONF_VIA_HUB = 'via_hub'
CONF_VIA_DEVICE = 'via_device'
CONF_DEPRECATED_VIA_HUB = 'via_hub'

PROTOCOL_31 = '3.1'
PROTOCOL_311 = '3.1.1'
Expand Down Expand Up @@ -229,17 +230,20 @@ def embedded_broker_deprecated(value):
default=DEFAULT_PAYLOAD_NOT_AVAILABLE): cv.string,
})

MQTT_ENTITY_DEVICE_INFO_SCHEMA = vol.All(vol.Schema({
vol.Optional(CONF_IDENTIFIERS, default=list):
vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_CONNECTIONS, default=list):
vol.All(cv.ensure_list, [vol.All(vol.Length(2), [cv.string])]),
vol.Optional(CONF_MANUFACTURER): cv.string,
vol.Optional(CONF_MODEL): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_SW_VERSION): cv.string,
vol.Optional(CONF_VIA_HUB): cv.string,
}), validate_device_has_at_least_one_identifier)
MQTT_ENTITY_DEVICE_INFO_SCHEMA = vol.All(
cv.deprecated(CONF_DEPRECATED_VIA_HUB, CONF_VIA_DEVICE),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecate the old config option.

vol.Schema({
vol.Optional(CONF_IDENTIFIERS, default=list):
vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_CONNECTIONS, default=list):
vol.All(cv.ensure_list, [vol.All(vol.Length(2), [cv.string])]),
vol.Optional(CONF_MANUFACTURER): cv.string,
vol.Optional(CONF_MODEL): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_SW_VERSION): cv.string,
vol.Optional(CONF_VIA_DEVICE): cv.string,
}),
validate_device_has_at_least_one_identifier)

MQTT_JSON_ATTRS_SCHEMA = vol.Schema({
vol.Optional(CONF_JSON_ATTRS_TOPIC): valid_subscribe_topic,
Expand Down Expand Up @@ -1098,8 +1102,8 @@ def device_info(self):
if CONF_SW_VERSION in self._device_config:
info['sw_version'] = self._device_config[CONF_SW_VERSION]

if CONF_VIA_HUB in self._device_config:
info['via_hub'] = (DOMAIN, self._device_config[CONF_VIA_HUB])
if CONF_VIA_DEVICE in self._device_config:
info['via_device'] = (DOMAIN, self._device_config[CONF_VIA_DEVICE])

return info

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/point/__init__.py
Expand Up @@ -300,7 +300,7 @@ def device_info(self):
'model': 'Point v{}'.format(device['hardware_version']),
'name': device['description'],
'sw_version': device['firmware']['installed'],
'via_hub': (DOMAIN, device['home']),
'via_device': (DOMAIN, device['home']),
}

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tellduslive/entry.py
Expand Up @@ -128,5 +128,5 @@ def device_info(self):
device_info['manufacturer'] = protocol.title()
client = device.get('client')
if client is not None:
device_info['via_hub'] = ('tellduslive', client)
device_info['via_device'] = ('tellduslive', client)
return device_info
16 changes: 8 additions & 8 deletions homeassistant/components/toon/__init__.py
Expand Up @@ -64,7 +64,7 @@ async def async_setup_entry(hass: HomeAssistantType,
},
manufacturer='Eneco',
name="Meter Adapter",
via_hub=(DOMAIN, toon.agreement.id)
via_device=(DOMAIN, toon.agreement.id)
)

for component in 'binary_sensor', 'climate', 'sensor':
Expand Down Expand Up @@ -126,7 +126,7 @@ def device_info(self) -> Dict[str, Any]:
'identifiers': {
(DOMAIN, self.toon.agreement.id, 'electricity'),
},
'via_hub': (DOMAIN, self.toon.agreement.id, 'meter_adapter'),
'via_device': (DOMAIN, self.toon.agreement.id, 'meter_adapter'),
}


Expand All @@ -136,16 +136,16 @@ class ToonGasMeterDeviceEntity(ToonEntity):
@property
def device_info(self) -> Dict[str, Any]:
"""Return device information about this entity."""
via_hub = 'meter_adapter'
via_device = 'meter_adapter'
if self.toon.gas.is_smart:
via_hub = 'electricity'
via_device = 'electricity'

return {
'name': 'Gas Meter',
'identifiers': {
(DOMAIN, self.toon.agreement.id, 'gas'),
},
'via_hub': (DOMAIN, self.toon.agreement.id, via_hub),
'via_device': (DOMAIN, self.toon.agreement.id, via_device),
}


Expand All @@ -160,7 +160,7 @@ def device_info(self) -> Dict[str, Any]:
'identifiers': {
(DOMAIN, self.toon.agreement.id, 'solar'),
},
'via_hub': (DOMAIN, self.toon.agreement.id, 'meter_adapter'),
'via_device': (DOMAIN, self.toon.agreement.id, 'meter_adapter'),
}


Expand All @@ -176,7 +176,7 @@ def device_info(self) -> Dict[str, Any]:
'identifiers': {
(DOMAIN, self.toon.agreement.id, 'boiler_module'),
},
'via_hub': (DOMAIN, self.toon.agreement.id),
'via_device': (DOMAIN, self.toon.agreement.id),
}


Expand All @@ -191,5 +191,5 @@ def device_info(self) -> Dict[str, Any]:
'identifiers': {
(DOMAIN, self.toon.agreement.id, 'boiler'),
},
'via_hub': (DOMAIN, self.toon.agreement.id, 'boiler_module'),
'via_device': (DOMAIN, self.toon.agreement.id, 'boiler_module'),
}
2 changes: 1 addition & 1 deletion homeassistant/components/tradfri/light.py
Expand Up @@ -175,7 +175,7 @@ def device_info(self):
'manufacturer': info.manufacturer,
'model': info.model_number,
'sw_version': info.firmware_version,
'via_hub': (TRADFRI_DOMAIN, self._gateway_id),
'via_device': (TRADFRI_DOMAIN, self._gateway_id),
}

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tradfri/switch.py
Expand Up @@ -61,7 +61,7 @@ def device_info(self):
'manufacturer': info.manufacturer,
'model': info.model_number,
'sw_version': info.firmware_version,
'via_hub': (TRADFRI_DOMAIN, self._gateway_id),
'via_device': (TRADFRI_DOMAIN, self._gateway_id),
}

async def async_added_to_hass(self):
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/zha/entity.py
Expand Up @@ -109,7 +109,8 @@ def device_info(self):
ATTR_MANUFACTURER: zha_device_info[ATTR_MANUFACTURER],
MODEL: zha_device_info[MODEL],
NAME: zha_device_info[NAME],
'via_hub': (DOMAIN, self.hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID]),
'via_device': (
DOMAIN, self.hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID]),
}

@property
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zwave/__init__.py
Expand Up @@ -1079,14 +1079,14 @@ def device_info(self):
info['identifiers'] = {
(DOMAIN, self.node_id, self.values.primary.instance, ),
}
info['via_hub'] = (DOMAIN, self.node_id, )
info['via_device'] = (DOMAIN, self.node_id, )
else:
info['name'] = node_name(self.node)
info['identifiers'] = {
(DOMAIN, self.node_id),
}
if self.node_id > 1:
info['via_hub'] = (DOMAIN, 1, )
info['via_device'] = (DOMAIN, 1, )
return info

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zwave/node_entity.py
Expand Up @@ -133,7 +133,7 @@ def device_info(self):
'name': node_name(self.node)
}
if self.node_id > 1:
info['via_hub'] = (DOMAIN, 1)
info['via_device'] = (DOMAIN, 1)
return info

def network_node_changed(self, node=None, value=None, args=None):
Expand Down
25 changes: 14 additions & 11 deletions homeassistant/helpers/device_registry.py
Expand Up @@ -38,7 +38,7 @@ class DeviceEntry:
model = attr.ib(type=str, default=None)
name = attr.ib(type=str, default=None)
sw_version = attr.ib(type=str, default=None)
hub_device_id = attr.ib(type=str, default=None)
via_device_id = attr.ib(type=str, default=None)
area_id = attr.ib(type=str, default=None)
name_by_user = attr.ib(type=str, default=None)
id = attr.ib(type=str, default=attr.Factory(lambda: uuid.uuid4().hex))
Expand Down Expand Up @@ -93,7 +93,7 @@ def async_get_device(self, identifiers: set, connections: set):
def async_get_or_create(self, *, config_entry_id, connections=None,
identifiers=None, manufacturer=_UNDEF,
model=_UNDEF, name=_UNDEF, sw_version=_UNDEF,
via_hub=None):
via_device=None):
"""Get device. Create if it doesn't exist."""
if not identifiers and not connections:
return None
Expand All @@ -116,16 +116,16 @@ def async_get_or_create(self, *, config_entry_id, connections=None,
device = DeviceEntry(is_new=True)
self.devices[device.id] = device

if via_hub is not None:
hub_device = self.async_get_device({via_hub}, set())
hub_device_id = hub_device.id if hub_device else _UNDEF
if via_device is not None:
via = self.async_get_device({via_device}, set())
via_device_id = via.id if via else _UNDEF
else:
hub_device_id = _UNDEF
via_device_id = _UNDEF

return self._async_update_device(
device.id,
add_config_entry_id=config_entry_id,
hub_device_id=hub_device_id,
via_device_id=via_device_id,
merge_connections=connections or _UNDEF,
merge_identifiers=identifiers or _UNDEF,
manufacturer=manufacturer,
Expand Down Expand Up @@ -153,7 +153,7 @@ def _async_update_device(self, device_id, *, add_config_entry_id=_UNDEF,
model=_UNDEF,
name=_UNDEF,
sw_version=_UNDEF,
hub_device_id=_UNDEF,
via_device_id=_UNDEF,
area_id=_UNDEF,
name_by_user=_UNDEF):
"""Update device attributes."""
Expand Down Expand Up @@ -191,7 +191,7 @@ def _async_update_device(self, device_id, *, add_config_entry_id=_UNDEF,
('model', model),
('name', name),
('sw_version', sw_version),
('hub_device_id', hub_device_id),
('via_device_id', via_device_id),
):
if value is not _UNDEF and value != getattr(old, attr_name):
changes[attr_name] = value
Expand Down Expand Up @@ -247,7 +247,10 @@ async def async_load(self):
sw_version=device['sw_version'],
id=device['id'],
# Introduced in 0.79
hub_device_id=device.get('hub_device_id'),
# renamed in 0.95
via_device_id=(
device.get('via_device_id')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This automatically upgrades the existing device registry on loading. Alternately we could do an update script instead, what's better here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot smaller than adding a script 👍 . Just make renamed -> Renamed

or device.get('hub_device_id')),
# Introduced in 0.87
area_id=device.get('area_id'),
name_by_user=device.get('name_by_user')
Expand Down Expand Up @@ -275,7 +278,7 @@ def _data_to_save(self):
'name': entry.name,
'sw_version': entry.sw_version,
'id': entry.id,
'hub_device_id': entry.hub_device_id,
'via_device_id': entry.via_device_id,
'area_id': entry.area_id,
'name_by_user': entry.name_by_user
} for entry in self.devices.values()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity_platform.py
Expand Up @@ -296,7 +296,7 @@ async def _async_add_entity(self, entity, update_before_add,
'model',
'name',
'sw_version',
'via_hub',
'via_device',
):
if key in device_info:
processed_dev_info[key] = device_info[key]
Expand Down
6 changes: 3 additions & 3 deletions tests/components/config/test_device_registry.py
Expand Up @@ -29,7 +29,7 @@ async def test_list_devices(hass, client, registry):
config_entry_id='1234',
identifiers={('bridgeid', '1234')},
manufacturer='manufacturer', model='model',
via_hub=('bridgeid', '0123'))
via_device=('bridgeid', '0123'))

await client.send_json({
'id': 5,
Expand All @@ -47,7 +47,7 @@ async def test_list_devices(hass, client, registry):
'model': 'model',
'name': None,
'sw_version': None,
'hub_device_id': None,
'via_device_id': None,
'area_id': None,
'name_by_user': None,
},
Expand All @@ -58,7 +58,7 @@ async def test_list_devices(hass, client, registry):
'model': 'model',
'name': None,
'sw_version': None,
'hub_device_id': dev1,
'via_device_id': dev1,
'area_id': None,
'name_by_user': None,
}
Expand Down
Expand Up @@ -51,4 +51,4 @@ async def test_aqara_gateway_setup(hass):
assert device.name == 'Aqara Hub-1563'
assert device.model == 'ZHWA11LM'
assert device.sw_version == '1.4.7'
assert device.hub_device_id is None
assert device.via_device_id is None
Expand Up @@ -74,7 +74,7 @@ async def test_ecobee3_setup(hass):
assert climate_device.name == 'HomeW'
assert climate_device.model == 'ecobee3'
assert climate_device.sw_version == '4.2.394'
assert climate_device.hub_device_id is None
assert climate_device.via_device_id is None

# Check that an attached sensor has its own device entity that
# is linked to the bridge
Expand All @@ -83,7 +83,7 @@ async def test_ecobee3_setup(hass):
assert sensor_device.name == 'Kitchen'
assert sensor_device.model == 'REMOTE SENSOR'
assert sensor_device.sw_version == '1.0.0'
assert sensor_device.hub_device_id == climate_device.id
assert sensor_device.via_device_id == climate_device.id


async def test_ecobee3_setup_from_cache(hass, hass_storage):
Expand Down
Expand Up @@ -45,7 +45,7 @@ async def test_koogeek_ls1_setup(hass):
assert device.name == 'Koogeek-LS1-20833F'
assert device.model == 'LS1'
assert device.sw_version == '2.2.15'
assert device.hub_device_id is None
assert device.via_device_id is None


@pytest.mark.parametrize('failure_cls', [
Expand Down
Expand Up @@ -38,4 +38,4 @@ async def test_lennox_e30_setup(hass):

# The fixture contains a single accessory - so its a single device
# and no bridge
assert device.hub_device_id is None
assert device.via_device_id is None