Add `device_info` property to OpenWeatherMap entities (#49293)

pull/49308/head^2
Maciej Bieniek 2021-04-16 18:28:53 +02:00 committed by GitHub
parent 7264c95217
commit e9cf8db302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 1 deletions

View File

@ -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."""

View File

@ -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"

View File

@ -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."""