From 39fefa49cc37749574042e342aebdbdf11975749 Mon Sep 17 00:00:00 2001 From: Xiaonan Shen Date: Thu, 7 May 2020 10:04:13 -0700 Subject: [PATCH] Fix roomba 980 position report (#35316) --- homeassistant/components/roomba/__init__.py | 1 - homeassistant/components/roomba/binary_sensor.py | 4 ++++ homeassistant/components/roomba/irobot_base.py | 13 ++++++++++++- homeassistant/components/roomba/sensor.py | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/roomba/__init__.py b/homeassistant/components/roomba/__init__.py index 9fb93211576..90c7c06b387 100644 --- a/homeassistant/components/roomba/__init__.py +++ b/homeassistant/components/roomba/__init__.py @@ -95,7 +95,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): diff --git a/homeassistant/components/roomba/binary_sensor.py b/homeassistant/components/roomba/binary_sensor.py index 47212563b5b..49e3da1d8de 100644 --- a/homeassistant/components/roomba/binary_sensor.py +++ b/homeassistant/components/roomba/binary_sensor.py @@ -45,3 +45,7 @@ class RoombaBinStatus(IRobotEntity, BinarySensorDevice): 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 diff --git a/homeassistant/components/roomba/irobot_base.py b/homeassistant/components/roomba/irobot_base.py index 4ebe580e7b2..2df5bf2abbf 100644 --- a/homeassistant/components/roomba/irobot_base.py +++ b/homeassistant/components/roomba/irobot_base.py @@ -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, StateVacuumDevice): @@ -212,6 +218,11 @@ class IRobotVacuum(IRobotEntity, StateVacuumDevice): 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() diff --git a/homeassistant/components/roomba/sensor.py b/homeassistant/components/roomba/sensor.py index 1a10c429321..40dbd52e158 100644 --- a/homeassistant/components/roomba/sensor.py +++ b/homeassistant/components/roomba/sensor.py @@ -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