Fix for unavailable units during initial startup

This commit is contained in:
Diogo Gomes
2018-02-25 02:07:14 +00:00
parent f489bff582
commit 865b866c04

View File

@@ -119,25 +119,20 @@ class SensorFilter(Entity):
self._state = new_state.state
for filt in self._filters:
try:
filtered_state = filt.filter_state(self._state)
_LOGGER.debug("%s(%s) -> %s", filt.name, self._state,
filtered_state)
self._state = filtered_state
filt.states.append(filtered_state)
except ValueError:
_LOGGER.warning("Could not convert state to number")
self.async_schedule_update_ha_state(True)
@callback
def filter_sensor_startup(event):
"""Update filter on startup."""
async_track_state_change(
self.hass, self._entity, filter_sensor_state_listener)
self.async_schedule_update_ha_state(True)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, filter_sensor_startup)
@property
def name(self):
"""Return the name of the sensor."""
@@ -167,7 +162,6 @@ class SensorFilter(Entity):
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {
ATTR_UNIT_OF_MEASUREMENT: self._unit_of_measurement,
ATTR_ENTITY_ID: self._entity
}
for filt in self._filters: