diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index 47859b78812..15935556ef3 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -161,6 +161,8 @@ async def async_setup_entry( """Set up OpenWeatherMap sensor entities based on a config entry.""" domain_data = config_entry.runtime_data name = domain_data.name + unique_id = config_entry.unique_id + assert unique_id is not None weather_coordinator = domain_data.coordinator if domain_data.mode == OWM_MODE_FREE_FORECAST: @@ -174,7 +176,7 @@ async def async_setup_entry( async_add_entities( OpenWeatherMapSensor( name, - f"{config_entry.unique_id}-{description.key}", + unique_id, description, weather_coordinator, ) @@ -200,11 +202,10 @@ class AbstractOpenWeatherMapSensor(SensorEntity): self._coordinator = coordinator self._attr_name = f"{name} {description.name}" - self._attr_unique_id = unique_id - split_unique_id = unique_id.split("-") + self._attr_unique_id = f"{unique_id}-{description.key}" self._attr_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, - identifiers={(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")}, + identifiers={(DOMAIN, unique_id)}, manufacturer=MANUFACTURER, name=DEFAULT_NAME, )