mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Use shorthand attribute for native_value in mold_indicator (#129538)
This commit is contained in:
parent
b1d48fe9a2
commit
4c2c01b4f6
@ -37,7 +37,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.device import async_device_info_to_link_from_entity
|
from homeassistant.helpers.device import async_device_info_to_link_from_entity
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_state_change_event
|
from homeassistant.helpers.event import async_track_state_change_event
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||||
|
|
||||||
@ -150,7 +150,6 @@ class MoldIndicator(SensorEntity):
|
|||||||
unique_id: str | None,
|
unique_id: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._state: str | None = None
|
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
self._attr_unique_id = unique_id
|
self._attr_unique_id = unique_id
|
||||||
self._indoor_temp_sensor = indoor_temp_sensor
|
self._indoor_temp_sensor = indoor_temp_sensor
|
||||||
@ -272,7 +271,7 @@ class MoldIndicator(SensorEntity):
|
|||||||
# re-calculate dewpoint and mold indicator
|
# re-calculate dewpoint and mold indicator
|
||||||
self._calc_dewpoint()
|
self._calc_dewpoint()
|
||||||
self._calc_moldindicator()
|
self._calc_moldindicator()
|
||||||
if self._state is None:
|
if self._attr_native_value is None:
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
else:
|
else:
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
@ -401,7 +400,7 @@ class MoldIndicator(SensorEntity):
|
|||||||
# re-calculate dewpoint and mold indicator
|
# re-calculate dewpoint and mold indicator
|
||||||
self._calc_dewpoint()
|
self._calc_dewpoint()
|
||||||
self._calc_moldindicator()
|
self._calc_moldindicator()
|
||||||
if self._state is None:
|
if self._attr_native_value is None:
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
self._dewpoint = None
|
self._dewpoint = None
|
||||||
self._crit_temp = None
|
self._crit_temp = None
|
||||||
@ -437,7 +436,7 @@ class MoldIndicator(SensorEntity):
|
|||||||
self._dewpoint,
|
self._dewpoint,
|
||||||
self._calib_factor,
|
self._calib_factor,
|
||||||
)
|
)
|
||||||
self._state = None
|
self._attr_native_value = None
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
self._crit_temp = None
|
self._crit_temp = None
|
||||||
return
|
return
|
||||||
@ -468,18 +467,13 @@ class MoldIndicator(SensorEntity):
|
|||||||
|
|
||||||
# check bounds and format
|
# check bounds and format
|
||||||
if crit_humidity > 100:
|
if crit_humidity > 100:
|
||||||
self._state = "100"
|
self._attr_native_value = "100"
|
||||||
elif crit_humidity < 0:
|
elif crit_humidity < 0:
|
||||||
self._state = "0"
|
self._attr_native_value = "0"
|
||||||
else:
|
else:
|
||||||
self._state = f"{int(crit_humidity):d}"
|
self._attr_native_value = f"{int(crit_humidity):d}"
|
||||||
|
|
||||||
_LOGGER.debug("Mold indicator humidity: %s", self._state)
|
_LOGGER.debug("Mold indicator humidity: %s", self.native_value)
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self) -> StateType:
|
|
||||||
"""Return the state of the entity."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user