Add `device_info` property to OpenWeatherMap entities (#49293)
parent
7264c95217
commit
e9cf8db302
|
@ -3,7 +3,15 @@ from homeassistant.components.sensor import SensorEntity
|
|||
from homeassistant.const import ATTR_ATTRIBUTION
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import ATTRIBUTION, SENSOR_DEVICE_CLASS, SENSOR_NAME, SENSOR_UNIT
|
||||
from .const import (
|
||||
ATTRIBUTION,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
SENSOR_DEVICE_CLASS,
|
||||
SENSOR_NAME,
|
||||
SENSOR_UNIT,
|
||||
)
|
||||
|
||||
|
||||
class AbstractOpenWeatherMapSensor(SensorEntity):
|
||||
|
@ -36,6 +44,17 @@ class AbstractOpenWeatherMapSensor(SensorEntity):
|
|||
"""Return a unique_id for this entity."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
split_unique_id = self._unique_id.split("-")
|
||||
return {
|
||||
"identifiers": {(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"entry_type": "service",
|
||||
}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement of the entity."""
|
||||
|
|
|
@ -42,6 +42,7 @@ DOMAIN = "openweathermap"
|
|||
DEFAULT_NAME = "OpenWeatherMap"
|
||||
DEFAULT_LANGUAGE = "en"
|
||||
ATTRIBUTION = "Data provided by OpenWeatherMap"
|
||||
MANUFACTURER = "OpenWeather"
|
||||
CONF_LANGUAGE = "language"
|
||||
CONFIG_FLOW_VERSION = 2
|
||||
ENTRY_NAME = "name"
|
||||
|
|
|
@ -12,9 +12,11 @@ from .const import (
|
|||
ATTR_API_WIND_BEARING,
|
||||
ATTR_API_WIND_SPEED,
|
||||
ATTRIBUTION,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
ENTRY_NAME,
|
||||
ENTRY_WEATHER_COORDINATOR,
|
||||
MANUFACTURER,
|
||||
)
|
||||
from .weather_update_coordinator import WeatherUpdateCoordinator
|
||||
|
||||
|
@ -55,6 +57,16 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||
"""Return a unique_id for this entity."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._unique_id)},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"entry_type": "service",
|
||||
}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement of the entity."""
|
||||
|
|
Loading…
Reference in New Issue