mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Avoid split of unique id to build OpenWeatherMap sensors (#144546)
* Avoid split of unique id * Assert that unique_id is not None
This commit is contained in:
parent
9a2f17c2b2
commit
a7afeb078c
@ -161,6 +161,8 @@ async def async_setup_entry(
|
|||||||
"""Set up OpenWeatherMap sensor entities based on a config entry."""
|
"""Set up OpenWeatherMap sensor entities based on a config entry."""
|
||||||
domain_data = config_entry.runtime_data
|
domain_data = config_entry.runtime_data
|
||||||
name = domain_data.name
|
name = domain_data.name
|
||||||
|
unique_id = config_entry.unique_id
|
||||||
|
assert unique_id is not None
|
||||||
weather_coordinator = domain_data.coordinator
|
weather_coordinator = domain_data.coordinator
|
||||||
|
|
||||||
if domain_data.mode == OWM_MODE_FREE_FORECAST:
|
if domain_data.mode == OWM_MODE_FREE_FORECAST:
|
||||||
@ -174,7 +176,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
OpenWeatherMapSensor(
|
OpenWeatherMapSensor(
|
||||||
name,
|
name,
|
||||||
f"{config_entry.unique_id}-{description.key}",
|
unique_id,
|
||||||
description,
|
description,
|
||||||
weather_coordinator,
|
weather_coordinator,
|
||||||
)
|
)
|
||||||
@ -200,11 +202,10 @@ class AbstractOpenWeatherMapSensor(SensorEntity):
|
|||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
|
|
||||||
self._attr_name = f"{name} {description.name}"
|
self._attr_name = f"{name} {description.name}"
|
||||||
self._attr_unique_id = unique_id
|
self._attr_unique_id = f"{unique_id}-{description.key}"
|
||||||
split_unique_id = unique_id.split("-")
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")},
|
identifiers={(DOMAIN, unique_id)},
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
name=DEFAULT_NAME,
|
name=DEFAULT_NAME,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user