Fix roomba 980 position report ()

pull/35347/head
Xiaonan Shen 2020-05-07 10:04:13 -07:00 committed by GitHub
parent a38bb5b33b
commit 9d5704307a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View File

@ -98,7 +98,6 @@ async def async_setup_entry(hass, config_entry):
continuous=config_entry.options[CONF_CONTINUOUS],
delay=config_entry.options[CONF_DELAY],
)
roomba.exclude = "wifistat" # ignore wifistat to avoid unnecessary updates
try:
if not await async_connect_or_timeout(hass, roomba):

View File

@ -45,3 +45,7 @@ class RoombaBinStatus(IRobotEntity, BinarySensorEntity):
def state(self):
"""Return the state of the sensor."""
return roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
def new_state_filter(self, new_state):
"""Filter the new state."""
return "bin" in new_state

View File

@ -102,9 +102,15 @@ class IRobotEntity(Entity):
"""Register callback function."""
self.vacuum.register_on_message_callback(self.on_message)
def new_state_filter(self, new_state):
"""Filter the new state."""
raise NotImplementedError
def on_message(self, json_data):
"""Update state on message change."""
self.schedule_update_ha_state()
state = json_data.get("state", {}).get("reported", {})
if self.new_state_filter(state):
self.schedule_update_ha_state()
class IRobotVacuum(IRobotEntity, StateVacuumEntity):
@ -212,6 +218,11 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
def on_message(self, json_data):
"""Update state on message change."""
new_state = json_data.get("state", {}).get("reported", {})
if (
len(new_state) == 1 and "signal" in new_state
): # filter out wifi stat messages
return
_LOGGER.debug("Got new state from the vacuum: %s", json_data)
self.vacuum_state = roomba_reported_state(self.vacuum)
self.schedule_update_ha_state()

View File

@ -46,3 +46,7 @@ class RoombaBattery(IRobotEntity):
def state(self):
"""Return the state of the sensor."""
return roomba_reported_state(self.vacuum).get("batPct")
def new_state_filter(self, new_state):
"""Filter the new state."""
return "batPct" in new_state