Add workaround for missing cleaning time in roomba (#51163)

pull/51551/head
drinfernoo 2021-06-06 03:13:35 -07:00 committed by GitHub
parent e560e623e9
commit 5bbf0ca6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 8 deletions

View File

@ -23,6 +23,7 @@ from homeassistant.components.vacuum import (
)
import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util
from . import roomba_reported_state
from .const import DOMAIN
@ -191,14 +192,10 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
# currently on
if self.state == STATE_CLEANING:
# Get clean mission status
mission_state = state.get("cleanMissionStatus", {})
cleaning_time = mission_state.get("mssnM")
cleaned_area = mission_state.get("sqft") # Imperial
# Convert to m2 if the unit_system is set to metric
if cleaned_area and self.hass.config.units.is_metric:
cleaned_area = round(cleaned_area * 0.0929)
state_attrs[ATTR_CLEANING_TIME] = cleaning_time
state_attrs[ATTR_CLEANED_AREA] = cleaned_area
(
state_attrs[ATTR_CLEANING_TIME],
state_attrs[ATTR_CLEANED_AREA],
) = self.get_cleaning_status(state)
# Error
if self.vacuum.error_code != 0:
@ -219,6 +216,25 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
return state_attrs
def get_cleaning_status(self, state) -> tuple[int, int]:
"""Return the cleaning time and cleaned area from the device."""
if not (mission_state := state.get("cleanMissionStatus")):
return (0, 0)
if cleaning_time := mission_state.get("mssnM", 0):
pass
elif start_time := mission_state.get("mssnStrtTm"):
now = dt_util.as_timestamp(dt_util.utcnow())
if now > start_time:
cleaning_time = (now - start_time) // 60
if cleaned_area := mission_state.get("sqft", 0): # Imperial
# Convert to m2 if the unit_system is set to metric
if self.hass.config.units.is_metric:
cleaned_area = round(cleaned_area * 0.0929)
return (cleaning_time, cleaned_area)
def on_message(self, json_data):
"""Update state on message change."""
state = json_data.get("state", {}).get("reported", {})