Use shorthand attributes in NWS (#99620)
This commit is contained in:
parent
9c775a8a24
commit
69ac8a0a2b
2 changed files with 15 additions and 51 deletions
|
@ -23,7 +23,6 @@ from homeassistant.const import (
|
|||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
@ -163,6 +162,7 @@ class NWSSensor(CoordinatorEntity[NwsDataUpdateCoordinator], SensorEntity):
|
|||
|
||||
entity_description: NWSSensorEntityDescription
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_entity_registry_enabled_default = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -175,13 +175,17 @@ class NWSSensor(CoordinatorEntity[NwsDataUpdateCoordinator], SensorEntity):
|
|||
"""Initialise the platform with a data instance."""
|
||||
super().__init__(nws_data.coordinator_observation)
|
||||
self._nws = nws_data.api
|
||||
self._latitude = entry_data[CONF_LATITUDE]
|
||||
self._longitude = entry_data[CONF_LONGITUDE]
|
||||
latitude = entry_data[CONF_LATITUDE]
|
||||
longitude = entry_data[CONF_LONGITUDE]
|
||||
self.entity_description = description
|
||||
|
||||
self._attr_name = f"{station} {description.name}"
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_native_unit_of_measurement = description.unit_convert
|
||||
self._attr_device_info = device_info(latitude, longitude)
|
||||
self._attr_unique_id = (
|
||||
f"{base_unique_id(latitude, longitude)}_{description.key}"
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
|
@ -219,11 +223,6 @@ class NWSSensor(CoordinatorEntity[NwsDataUpdateCoordinator], SensorEntity):
|
|||
return round(value)
|
||||
return value
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique_id for this entity."""
|
||||
return f"{base_unique_id(self._latitude, self._longitude)}_{self.entity_description.key}"
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if state is available."""
|
||||
|
@ -235,13 +234,3 @@ class NWSSensor(CoordinatorEntity[NwsDataUpdateCoordinator], SensorEntity):
|
|||
else:
|
||||
last_success_time = False
|
||||
return self.coordinator.last_update_success or last_success_time
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return False
|
||||
|
||||
@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