Fix roomba 980 position report (#35316)
parent
a38bb5b33b
commit
9d5704307a
homeassistant/components/roomba
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue