Code fixes and cleanup for roomba integration (#34409)
* Remove side effects from properties * Remove redundant return value in async_send_command * Move callback registeration to async_added_to_hass * Code cleanup for roomba
This commit is contained in:
parent
7a8d1c00a4
commit
2686869f88
4 changed files with 4 additions and 16 deletions
|
@ -18,7 +18,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
status = roomba_reported_state(roomba).get("bin", {})
|
status = roomba_reported_state(roomba).get("bin", {})
|
||||||
if "full" in status:
|
if "full" in status:
|
||||||
roomba_vac = RoombaBinStatus(roomba, blid)
|
roomba_vac = RoombaBinStatus(roomba, blid)
|
||||||
roomba_vac.register_callback()
|
|
||||||
async_add_entities([roomba_vac], True)
|
async_add_entities([roomba_vac], True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,8 +44,4 @@ class RoombaBinStatus(IRobotEntity, BinarySensorDevice):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
bin_status = (
|
return roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
|
||||||
roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
|
|
||||||
)
|
|
||||||
_LOGGER.debug("Update Full Bin status from the vacuum: %s", bin_status)
|
|
||||||
return bin_status
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class IRobotEntity(Entity):
|
||||||
"model": self._sku,
|
"model": self._sku,
|
||||||
}
|
}
|
||||||
|
|
||||||
def register_callback(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register callback function."""
|
"""Register callback function."""
|
||||||
self.vacuum.register_on_message_callback(self.on_message)
|
self.vacuum.register_on_message_callback(self.on_message)
|
||||||
|
|
||||||
|
@ -207,9 +207,7 @@ class IRobotVacuum(IRobotEntity, StateVacuumDevice):
|
||||||
def on_message(self, json_data):
|
def on_message(self, json_data):
|
||||||
"""Update state on message change."""
|
"""Update state on message change."""
|
||||||
_LOGGER.debug("Got new state from the vacuum: %s", json_data)
|
_LOGGER.debug("Got new state from the vacuum: %s", json_data)
|
||||||
self.vacuum_state = self.vacuum.master_state.get("state", {}).get(
|
self.vacuum_state = roomba_reported_state(self.vacuum)
|
||||||
"reported", {}
|
|
||||||
)
|
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_start(self):
|
async def async_start(self):
|
||||||
|
@ -247,4 +245,3 @@ class IRobotVacuum(IRobotEntity, StateVacuumDevice):
|
||||||
await self.hass.async_add_executor_job(
|
await self.hass.async_add_executor_job(
|
||||||
self.vacuum.send_command, command, params
|
self.vacuum.send_command, command, params
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
roomba = domain_data[ROOMBA_SESSION]
|
roomba = domain_data[ROOMBA_SESSION]
|
||||||
blid = domain_data[BLID]
|
blid = domain_data[BLID]
|
||||||
roomba_vac = RoombaBattery(roomba, blid)
|
roomba_vac = RoombaBattery(roomba, blid)
|
||||||
roomba_vac.register_callback()
|
|
||||||
async_add_entities([roomba_vac], True)
|
async_add_entities([roomba_vac], True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +45,4 @@ class RoombaBattery(IRobotEntity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
battery_level = roomba_reported_state(self.vacuum).get("batPct")
|
return roomba_reported_state(self.vacuum).get("batPct")
|
||||||
_LOGGER.debug("Update battery level status from the vacuum: %s", battery_level)
|
|
||||||
return battery_level
|
|
||||||
|
|
|
@ -28,5 +28,4 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
constructor = RoombaVacuum
|
constructor = RoombaVacuum
|
||||||
|
|
||||||
roomba_vac = constructor(roomba, blid)
|
roomba_vac = constructor(roomba, blid)
|
||||||
roomba_vac.register_callback()
|
|
||||||
async_add_entities([roomba_vac], True)
|
async_add_entities([roomba_vac], True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue