mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Make threshold binary sensor faster (#43695)
This commit is contained in:
parent
5d7d2dee2a
commit
898a07fa75
@ -71,7 +71,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
hass, entity_id, name, lower, upper, hysteresis, device_class
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
@ -88,8 +87,8 @@ class ThresholdSensor(BinarySensorEntity):
|
||||
self._hysteresis = hysteresis
|
||||
self._device_class = device_class
|
||||
|
||||
self._state_position = None
|
||||
self._state = False
|
||||
self._state_position = POSITION_UNKNOWN
|
||||
self._state = None
|
||||
self.sensor_value = None
|
||||
|
||||
@callback
|
||||
@ -107,7 +106,8 @@ class ThresholdSensor(BinarySensorEntity):
|
||||
self.sensor_value = None
|
||||
_LOGGER.warning("State is not numerical")
|
||||
|
||||
hass.async_add_job(self.async_update_ha_state, True)
|
||||
self._update_state()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async_track_state_change_event(
|
||||
hass, [entity_id], async_threshold_sensor_state_listener
|
||||
@ -156,8 +156,9 @@ class ThresholdSensor(BinarySensorEntity):
|
||||
ATTR_UPPER: self._threshold_upper,
|
||||
}
|
||||
|
||||
async def async_update(self):
|
||||
"""Get the latest data and updates the states."""
|
||||
@callback
|
||||
def _update_state(self):
|
||||
"""Update the state."""
|
||||
|
||||
def below(threshold):
|
||||
"""Determine if the sensor value is below a threshold."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user