Simplify get_unique_id helper function for zwave_js (#66221)

This commit is contained in:
Raman Gupta 2022-02-10 02:46:32 -05:00 committed by GitHub
parent 23e39d62d4
commit 72acda81a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 15 deletions

View File

@ -446,9 +446,7 @@ async def async_setup_entry( # noqa: C901
# We assert because we know the device exists
assert device
unique_id = get_unique_id(
client.driver.controller.home_id, disc_info.primary_value.value_id
)
unique_id = get_unique_id(client, disc_info.primary_value.value_id)
entity_id = ent_reg.async_get_entity_id(disc_info.platform, DOMAIN, unique_id)
raw_value = value_ = value.value

View File

@ -48,7 +48,7 @@ class ZWaveBaseEntity(Entity):
# Entity class attributes
self._attr_name = self.generate_name()
self._attr_unique_id = get_unique_id(
self.client.driver.controller.home_id, self.info.primary_value.value_id
self.client, self.info.primary_value.value_id
)
self._attr_entity_registry_enabled_default = (
self.info.entity_registry_enabled_default

View File

@ -55,9 +55,9 @@ def update_data_collection_preference(
@callback
def get_unique_id(home_id: str, value_id: str) -> str:
"""Get unique ID from home ID and value ID."""
return f"{home_id}.{value_id}"
def get_unique_id(client: ZwaveClient, value_id: str) -> str:
"""Get unique ID from client and value ID."""
return f"{client.driver.controller.home_id}.{value_id}"
@callback

View File

@ -470,10 +470,7 @@ def async_migrate_discovered_value(
) -> None:
"""Migrate unique ID for entity/entities tied to discovered value."""
new_unique_id = get_unique_id(
client.driver.controller.home_id,
disc_info.primary_value.value_id,
)
new_unique_id = get_unique_id(client, disc_info.primary_value.value_id)
# On reinterviews, there is no point in going through this logic again for already
# discovered values
@ -485,10 +482,7 @@ def async_migrate_discovered_value(
# 2021.2.*, 2021.3.0b0, and 2021.3.0 formats
old_unique_ids = [
get_unique_id(
client.driver.controller.home_id,
value_id,
)
get_unique_id(client, value_id)
for value_id in get_old_value_ids(disc_info.primary_value)
]