diff --git a/manifest.json b/manifest.json index 11032f3..f8282aa 100755 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "domain": "fmi", - "version": "0.4.7", + "version": "0.4.8", "name": "Finnish Meteorological Institute", "documentation": "https://www.home-assistant.io/integrations/fmi/", "requirements": [ diff --git a/weather.py b/weather.py index 7944c86..499fd1e 100755 --- a/weather.py +++ b/weather.py @@ -14,7 +14,8 @@ WeatherEntity, ) -from homeassistant.const import CONF_NAME +from awesomeversion import AwesomeVersion +from homeassistant.const import CONF_NAME, __version__ as HA_VERSION from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import CONF_DAILY_MODE @@ -29,6 +30,7 @@ PARALLEL_UPDATES = 1 +CURRENT_HA_VERSION = AwesomeVersion(HA_VERSION) async def async_setup_entry(hass, config_entry, async_add_entities): """Add an FMI weather entity from a config_entry.""" @@ -84,13 +86,23 @@ def unique_id(self): @property def device_info(self): """Return the device info.""" - return { + info = { "identifiers": {(DOMAIN, self.coordinator.unique_id)}, "name": NAME, "manufacturer": MANUFACTURER, - "entry_type": "service", } + # Legacy fallback can be removed when minimum required + # HA version is 2021.12. + if CURRENT_HA_VERSION >= "2021.12.0b0": + from homeassistant.helpers.device_registry import DeviceEntryType + + info["entry_type"] = DeviceEntryType.SERVICE + else: + info["entry_type"] = "service" + + return info + @property def available(self): """Return if weather data is available from FMI."""