mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Use entity class attributes for aemet (#52499)
This commit is contained in:
parent
3a2a688170
commit
4463d50711
@ -66,6 +66,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AbstractAemetSensor(CoordinatorEntity, SensorEntity):
|
class AbstractAemetSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Abstract class for an AEMET OpenData sensor."""
|
"""Abstract class for an AEMET OpenData sensor."""
|
||||||
|
|
||||||
|
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name,
|
name,
|
||||||
@ -80,33 +82,10 @@ class AbstractAemetSensor(CoordinatorEntity, SensorEntity):
|
|||||||
self._unique_id = unique_id
|
self._unique_id = unique_id
|
||||||
self._sensor_type = sensor_type
|
self._sensor_type = sensor_type
|
||||||
self._sensor_name = sensor_configuration[SENSOR_NAME]
|
self._sensor_name = sensor_configuration[SENSOR_NAME]
|
||||||
self._unit_of_measurement = sensor_configuration.get(SENSOR_UNIT)
|
self._attr_name = f"{self._name} {self._sensor_name}"
|
||||||
self._device_class = sensor_configuration.get(SENSOR_DEVICE_CLASS)
|
self._attr_unique_id = self._unique_id
|
||||||
|
self._attr_device_class = sensor_configuration.get(SENSOR_DEVICE_CLASS)
|
||||||
@property
|
self._attr_unit_of_measurement = sensor_configuration.get(SENSOR_UNIT)
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return f"{self._name} {self._sensor_name}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique_id for this entity."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device_class."""
|
|
||||||
return self._device_class
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return self._unit_of_measurement
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
return {ATTR_ATTRIBUTION: ATTRIBUTION}
|
|
||||||
|
|
||||||
|
|
||||||
class AemetSensor(AbstractAemetSensor):
|
class AemetSensor(AbstractAemetSensor):
|
||||||
@ -150,11 +129,9 @@ class AemetForecastSensor(AbstractAemetSensor):
|
|||||||
)
|
)
|
||||||
self._weather_coordinator = weather_coordinator
|
self._weather_coordinator = weather_coordinator
|
||||||
self._forecast_mode = forecast_mode
|
self._forecast_mode = forecast_mode
|
||||||
|
self._attr_entity_registry_enabled_default = (
|
||||||
@property
|
self._forecast_mode == FORECAST_MODE_DAILY
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
)
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
|
||||||
return self._forecast_mode == FORECAST_MODE_DAILY
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -39,6 +39,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AemetWeather(CoordinatorEntity, WeatherEntity):
|
class AemetWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Implementation of an AEMET OpenData sensor."""
|
"""Implementation of an AEMET OpenData sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name,
|
name,
|
||||||
@ -48,25 +51,18 @@ class AemetWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
):
|
):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._name = name
|
|
||||||
self._unique_id = unique_id
|
|
||||||
self._forecast_mode = forecast_mode
|
self._forecast_mode = forecast_mode
|
||||||
|
self._attr_entity_registry_enabled_default = (
|
||||||
@property
|
self._forecast_mode == FORECAST_MODE_DAILY
|
||||||
def attribution(self):
|
)
|
||||||
"""Return the attribution."""
|
self._attr_name = name
|
||||||
return ATTRIBUTION
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self):
|
||||||
"""Return the current condition."""
|
"""Return the current condition."""
|
||||||
return self.coordinator.data[ATTR_API_CONDITION]
|
return self.coordinator.data[ATTR_API_CONDITION]
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
|
||||||
return self._forecast_mode == FORECAST_MODE_DAILY
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def forecast(self):
|
def forecast(self):
|
||||||
"""Return the forecast array."""
|
"""Return the forecast array."""
|
||||||
@ -77,11 +73,6 @@ class AemetWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
"""Return the humidity."""
|
"""Return the humidity."""
|
||||||
return self.coordinator.data[ATTR_API_HUMIDITY]
|
return self.coordinator.data[ATTR_API_HUMIDITY]
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure(self):
|
def pressure(self):
|
||||||
"""Return the pressure."""
|
"""Return the pressure."""
|
||||||
@ -92,16 +83,6 @@ class AemetWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
"""Return the temperature."""
|
"""Return the temperature."""
|
||||||
return self.coordinator.data[ATTR_API_TEMPERATURE]
|
return self.coordinator.data[ATTR_API_TEMPERATURE]
|
||||||
|
|
||||||
@property
|
|
||||||
def temperature_unit(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique_id for this entity."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_bearing(self):
|
def wind_bearing(self):
|
||||||
"""Return the temperature."""
|
"""Return the temperature."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user