diff --git a/homeassistant/components/ipma/entity.py b/homeassistant/components/ipma/entity.py index 6424084c533..7eb8e2fe1a7 100644 --- a/homeassistant/components/ipma/entity.py +++ b/homeassistant/components/ipma/entity.py @@ -1,6 +1,9 @@ """Base Entity for IPMA.""" from __future__ import annotations +from pyipma.api import IPMA_API +from pyipma.location import Location + from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity import Entity @@ -10,17 +13,20 @@ from .const import DOMAIN class IPMADevice(Entity): """Common IPMA Device Information.""" - def __init__(self, location) -> None: + _attr_has_entity_name = True + + def __init__(self, api: IPMA_API, location: Location) -> None: """Initialize device information.""" + self._api = api self._location = location self._attr_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, identifiers={ ( DOMAIN, - f"{self._location.station_latitude}, {self._location.station_longitude}", + f"{location.station_latitude}, {location.station_longitude}", ) }, manufacturer=DOMAIN, - name=self._location.name, + name=location.name, ) diff --git a/homeassistant/components/ipma/sensor.py b/homeassistant/components/ipma/sensor.py index 1bd257a3994..7f5782f3f89 100644 --- a/homeassistant/components/ipma/sensor.py +++ b/homeassistant/components/ipma/sensor.py @@ -75,9 +75,8 @@ class IPMASensor(SensorEntity, IPMADevice): description: IPMASensorEntityDescription, ) -> None: """Initialize the IPMA Sensor.""" - IPMADevice.__init__(self, location) + IPMADevice.__init__(self, api, location) self.entity_description = description - self._api = api self._attr_unique_id = f"{self._location.station_latitude}, {self._location.station_longitude}, {self.entity_description.key}" @Throttle(MIN_TIME_BETWEEN_UPDATES) diff --git a/homeassistant/components/ipma/weather.py b/homeassistant/components/ipma/weather.py index 1f948bcc4e1..a5bb3981575 100644 --- a/homeassistant/components/ipma/weather.py +++ b/homeassistant/components/ipma/weather.py @@ -25,7 +25,6 @@ from homeassistant.components.weather import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_MODE, - CONF_NAME, UnitOfPressure, UnitOfSpeed, UnitOfTemperature, @@ -56,13 +55,14 @@ async def async_setup_entry( """Add a weather entity from a config_entry.""" api = hass.data[DOMAIN][config_entry.entry_id][DATA_API] location = hass.data[DOMAIN][config_entry.entry_id][DATA_LOCATION] - async_add_entities([IPMAWeather(location, api, config_entry.data)], True) + async_add_entities([IPMAWeather(api, location, config_entry)], True) class IPMAWeather(WeatherEntity, IPMADevice): """Representation of a weather condition.""" _attr_attribution = ATTRIBUTION + _attr_name = None _attr_native_pressure_unit = UnitOfPressure.HPA _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR @@ -70,13 +70,13 @@ class IPMAWeather(WeatherEntity, IPMADevice): WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY ) - def __init__(self, location: Location, api: IPMA_API, config) -> None: + def __init__( + self, api: IPMA_API, location: Location, config_entry: ConfigEntry + ) -> None: """Initialise the platform with a data instance and station name.""" - IPMADevice.__init__(self, location) - self._api = api - self._attr_name = config.get(CONF_NAME, location.name) - self._mode = config.get(CONF_MODE) - self._period = 1 if config.get(CONF_MODE) == "hourly" else 24 + IPMADevice.__init__(self, api, location) + self._mode = config_entry.data.get(CONF_MODE) + self._period = 1 if config_entry.data.get(CONF_MODE) == "hourly" else 24 self._observation = None self._daily_forecast: list[IPMAForecast] | None = None self._hourly_forecast: list[IPMAForecast] | None = None