Add device info to nws (#57153)
* Add base entity * Use function for device_info Multiple inheritance makes this tricky with a base class * Device info in sensor * Device info weather * parantheses * isort
This commit is contained in:
parent
0364405595
commit
fb063928ce
3 changed files with 24 additions and 2 deletions
|
@ -166,3 +166,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
if len(hass.data[DOMAIN]) == 0:
|
if len(hass.data[DOMAIN]) == 0:
|
||||||
hass.data.pop(DOMAIN)
|
hass.data.pop(DOMAIN)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
def device_info(latitude, longitude):
|
||||||
|
"""Return device registry information."""
|
||||||
|
return {
|
||||||
|
"identifiers": {(DOMAIN, base_unique_id(latitude, longitude))},
|
||||||
|
"name": f"NWS: {latitude}, {longitude}",
|
||||||
|
"manufacturer": "National Weather Service",
|
||||||
|
"entry_type": "service",
|
||||||
|
}
|
||||||
|
|
|
@ -14,12 +14,13 @@ from homeassistant.const import (
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.util.distance import convert as convert_distance
|
from homeassistant.util.distance import convert as convert_distance
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
from homeassistant.util.pressure import convert as convert_pressure
|
from homeassistant.util.pressure import convert as convert_pressure
|
||||||
|
|
||||||
from . import base_unique_id
|
from . import base_unique_id, device_info
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTRIBUTION,
|
ATTRIBUTION,
|
||||||
CONF_STATION,
|
CONF_STATION,
|
||||||
|
@ -117,3 +118,8 @@ class NWSSensor(CoordinatorEntity, SensorEntity):
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
"""Return device info."""
|
||||||
|
return device_info(self._latitude, self._longitude)
|
||||||
|
|
|
@ -23,13 +23,14 @@ from homeassistant.const import (
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.distance import convert as convert_distance
|
from homeassistant.util.distance import convert as convert_distance
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
from homeassistant.util.pressure import convert as convert_pressure
|
from homeassistant.util.pressure import convert as convert_pressure
|
||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
|
|
||||||
from . import base_unique_id
|
from . import base_unique_id, device_info
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_FORECAST_DAYTIME,
|
ATTR_FORECAST_DAYTIME,
|
||||||
ATTR_FORECAST_DETAILED_DESCRIPTION,
|
ATTR_FORECAST_DETAILED_DESCRIPTION,
|
||||||
|
@ -317,3 +318,8 @@ class NWSWeather(WeatherEntity):
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
return self.mode == DAYNIGHT
|
return self.mode == DAYNIGHT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
"""Return device info."""
|
||||||
|
return device_info(self.latitude, self.longitude)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue