ESPHome fix missing state in certain circumstances (#28729)

* Fix ESPHome having missing state in certain situations

Fixes https://github.com/esphome/issues/issues/828

* Update requirements_all

* Also fix climate preset mode
This commit is contained in:
Otto Winter 2019-11-12 18:26:46 +01:00 committed by Paulus Schoutsen
parent fc04b3e31c
commit a1f2b6d402
6 changed files with 10 additions and 4 deletions

View File

@ -44,6 +44,8 @@ class EsphomeBinarySensor(EsphomeEntity, BinarySensorDevice):
return self._entry_data.available return self._entry_data.available
if self._state is None: if self._state is None:
return None return None
if self._state.missing_state:
return None
return self._state.state return self._state.state
@property @property

View File

@ -138,7 +138,7 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
@esphome_state_property @esphome_state_property
def preset_mode(self): def preset_mode(self):
"""Return current preset mode.""" """Return current preset mode."""
return PRESET_AWAY if self._state.away else None return PRESET_AWAY if self._state.away else PRESET_HOME
@esphome_state_property @esphome_state_property
def current_temperature(self) -> Optional[float]: def current_temperature(self) -> Optional[float]:

View File

@ -4,7 +4,7 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome", "documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": [ "requirements": [
"aioesphomeapi==2.4.2" "aioesphomeapi==2.5.0"
], ],
"dependencies": [], "dependencies": [],
"zeroconf": ["_esphomelib._tcp.local."], "zeroconf": ["_esphomelib._tcp.local."],

View File

@ -67,6 +67,8 @@ class EsphomeSensor(EsphomeEntity):
"""Return the state of the entity.""" """Return the state of the entity."""
if math.isnan(self._state.state): if math.isnan(self._state.state):
return None return None
if self._state.missing_state:
return None
return "{:.{prec}f}".format( return "{:.{prec}f}".format(
self._state.state, prec=self._static_info.accuracy_decimals self._state.state, prec=self._static_info.accuracy_decimals
) )
@ -96,4 +98,6 @@ class EsphomeTextSensor(EsphomeEntity):
@esphome_state_property @esphome_state_property
def state(self) -> Optional[str]: def state(self) -> Optional[str]:
"""Return the state of the entity.""" """Return the state of the entity."""
if self._state.missing_state:
return None
return self._state.state return self._state.state

View File

@ -142,7 +142,7 @@ aiobotocore==0.10.2
aiodns==2.0.0 aiodns==2.0.0
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.4.2 aioesphomeapi==2.5.0
# homeassistant.components.freebox # homeassistant.components.freebox
aiofreepybox==0.0.8 aiofreepybox==0.0.8

View File

@ -50,7 +50,7 @@ aioautomatic==0.6.5
aiobotocore==0.10.2 aiobotocore==0.10.2
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.4.2 aioesphomeapi==2.5.0
# homeassistant.components.emulated_hue # homeassistant.components.emulated_hue
# homeassistant.components.http # homeassistant.components.http