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

* Return None if state is unknown

* Use None as initial state
pull/14412/head
damarco 2018-05-12 14:41:44 +02:00 committed by Martin Hjelmare
parent b903bbc042
commit 01ce43ec7c
6 changed files with 12 additions and 14 deletions

View File

@ -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)

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:

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)

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))

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)

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