mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Trend binary sensor check for state unavailable (#22621)
* Trend binary sensor check for state unavailable Fixes: https://github.com/home-assistant/home-assistant/issues/20210 * Fix pylint
This commit is contained in:
parent
0056fcf904
commit
431cc63aaf
@ -10,7 +10,7 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorDevice)
|
BinarySensorDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, CONF_DEVICE_CLASS, CONF_ENTITY_ID,
|
ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, CONF_DEVICE_CLASS, CONF_ENTITY_ID,
|
||||||
CONF_FRIENDLY_NAME, STATE_UNKNOWN, CONF_SENSORS)
|
CONF_FRIENDLY_NAME, STATE_UNKNOWN, STATE_UNAVAILABLE, CONF_SENSORS)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import generate_entity_id
|
from homeassistant.helpers.entity import generate_entity_id
|
||||||
@ -140,7 +140,7 @@ class SensorTrend(BinarySensorDevice):
|
|||||||
state = new_state.attributes.get(self._attribute)
|
state = new_state.attributes.get(self._attribute)
|
||||||
else:
|
else:
|
||||||
state = new_state.state
|
state = new_state.state
|
||||||
if state != STATE_UNKNOWN:
|
if state not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||||
sample = (utcnow().timestamp(), float(state))
|
sample = (utcnow().timestamp(), float(state))
|
||||||
self.samples.append(sample)
|
self.samples.append(sample)
|
||||||
self.async_schedule_update_ha_state(True)
|
self.async_schedule_update_ha_state(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user