Add Braava support to iRobot Roomba component (#33616)
* Add Braava support to iRobot Roomba component * Replace async_add_job with async_add_executor_job in roomba * Improve readability in roomba * Improve error handling in roomba * Cleanup async_update in roomba * Split into multiple files in roomba * Hide protocal details in braava * Switch to push in braava * Bump roombapy version to 1.5.1 * Add roomba files to .coveragerc * Fix typo * Remove side effects from init in roomba * Implement StateVacuumDevice in Roomba * Add IRobotEntity base class to braava * Fix state in roomba * Add @shenxn as a codeowner of braava
This commit is contained in:
1 parent
b3eba49a2f
commit
61a5793073
12 files changed
+520
-374
No files matched your search
@@ -2,10 +2,10 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.const import DEVICE_CLASS_BATTERY, UNIT_PERCENTAGE
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import roomba_reported_state
|
||||
from .const import BLID, DOMAIN, ROOMBA_SESSION
|
||||
from .irobot_base import IRobotEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,21 +16,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
roomba = domain_data[ROOMBA_SESSION]
|
||||
blid = domain_data[BLID]
|
||||
roomba_vac = RoombaBattery(roomba, blid)
|
||||
roomba_vac.register_callback()
|
||||
async_add_entities([roomba_vac], True)
|
||||
|
||||
|
||||
class RoombaBattery(Entity):
|
||||
class RoombaBattery(IRobotEntity):
|
||||
"""Class to hold Roomba Sensor basic info."""
|
||||
|
||||
def __init__(self, roomba, blid):
|
||||
"""Initialize the sensor object."""
|
||||
self.vacuum = roomba
|
||||
self.vacuum_state = roomba_reported_state(roomba)
|
||||
self._blid = blid
|
||||
self._name = self.vacuum_state.get("name")
|
||||
self._identifier = f"roomba_{self._blid}"
|
||||
self._battery_level = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
@@ -54,23 +46,6 @@ class RoombaBattery(Entity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._battery_level
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info of the vacuum cleaner."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._identifier)},
|
||||
"name": str(self._name),
|
||||
}
|
||||
|
||||
async def async_update(self):
|
||||
"""Return the update info of the vacuum cleaner."""
|
||||
# No data, no update
|
||||
if not self.vacuum.master_state:
|
||||
_LOGGER.debug("Roomba %s has no data yet. Skip update", self.name)
|
||||
return
|
||||
self._battery_level = roomba_reported_state(self.vacuum).get("batPct")
|
||||
_LOGGER.debug(
|
||||
"Update battery level status from the vacuum: %s", self._battery_level
|
||||
)
|
||||
battery_level = roomba_reported_state(self.vacuum).get("batPct")
|
||||
_LOGGER.debug("Update battery level status from the vacuum: %s", battery_level)
|
||||
return battery_level
|
||||
Reference in new issue
Block a user