Use None as initial state in zha component (#14389)

* Return None if state is unknown

* Use None as initial state
This commit is contained in:
damarco authored and Martin Hjelmare committed 2018-05-12 14:41:44 +02:00
1 parent b903bbc042
commit 01ce43ec7c
6 files changed
+12 -14

No files matched your search

@@ -108,7 +108,7 @@ class BinarySensor(zha.Entity, BinarySensorDevice):
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
if self._state == 'unknown':
if self._state is None:
return False
return bool(self._state)
+2 -3
View File
@@ -10,7 +10,6 @@ from homeassistant.components import zha
from homeassistant.components.fan import (
DOMAIN, FanEntity, SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
SUPPORT_SET_SPEED)
from homeassistant.const import STATE_UNKNOWN
DEPENDENCIES = ['zha']
@@ -72,7 +71,7 @@ class ZhaFan(zha.Entity, FanEntity):
@property
def is_on(self) -> bool:
"""Return true if entity is on."""
if self._state == STATE_UNKNOWN:
if self._state is None:
return False
return self._state != SPEED_OFF
@@ -103,7 +102,7 @@ class ZhaFan(zha.Entity, FanEntity):
"""Retrieve latest state."""
result = yield from zha.safe_read(self._endpoint.fan, ['fan_mode'])
new_value = result.get('fan_mode', None)
self._state = VALUE_TO_SPEED.get(new_value, STATE_UNKNOWN)
self._state = VALUE_TO_SPEED.get(new_value, None)
@property
def should_poll(self) -> bool:
+1 -2
View File
@@ -6,7 +6,6 @@ at https://home-assistant.io/components/light.zha/
"""
import logging
from homeassistant.components import light, zha
from homeassistant.const import STATE_UNKNOWN
import homeassistant.util.color as color_util
_LOGGER = logging.getLogger(__name__)
@@ -76,7 +75,7 @@ class Light(zha.Entity, light.Light):
@property
def is_on(self) -> bool:
"""Return true if entity is on."""
if self._state == STATE_UNKNOWN:
if self._state is None:
return False
return bool(self._state)
+6 -6
View File
@@ -102,8 +102,8 @@ class TemperatureSensor(Sensor):
@property
def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
if self._state is None:
return None
celsius = round(float(self._state) / 100, 1)
return convert_temperature(
celsius, TEMP_CELSIUS, self.unit_of_measurement)
@@ -122,8 +122,8 @@ class RelativeHumiditySensor(Sensor):
@property
def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
if self._state is None:
return None
return round(float(self._state) / 100, 1)
@@ -139,7 +139,7 @@ class PressureSensor(Sensor):
@property
def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
if self._state is None:
return None
return round(float(self._state))
+1 -1
View File
@@ -51,7 +51,7 @@ class Switch(zha.Entity, SwitchDevice):
@property
def is_on(self) -> bool:
"""Return if the switch is on based on the statemachine."""
if self._state == 'unknown':
if self._state is None:
return False
return bool(self._state)
+1 -1
View File
@@ -319,7 +319,7 @@ class Entity(entity.Entity):
self._endpoint = endpoint
self._in_clusters = in_clusters
self._out_clusters = out_clusters
self._state = ha_const.STATE_UNKNOWN
self._state = None
self._unique_id = unique_id
# Normally the entity itself is the listener. Sub-classes may set this