Fix Litterrobot available property (#71102)

This commit is contained in:
Shay Levy 2022-04-30 17:46:27 +03:00 committed by GitHub
parent 802c4c0d42
commit ae8604d429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@ from homeassistant.components.vacuum import (
VacuumEntityFeature, VacuumEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE from homeassistant.const import STATE_OFF
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -96,12 +96,14 @@ class LitterRobotCleaner(LitterRobotControlEntity, StateVacuumEntity):
| VacuumEntityFeature.TURN_ON | VacuumEntityFeature.TURN_ON
) )
@property
def available(self) -> bool:
"""Return True if the cleaner has been seen recently."""
return self.robot.last_seen > datetime.now(timezone.utc) - UNAVAILABLE_AFTER
@property @property
def state(self) -> str: def state(self) -> str:
"""Return the state of the cleaner.""" """Return the state of the cleaner."""
if self.robot.last_seen < datetime.now(timezone.utc) - UNAVAILABLE_AFTER:
return STATE_UNAVAILABLE
return LITTER_BOX_STATUS_STATE_MAP.get(self.robot.status, STATE_ERROR) return LITTER_BOX_STATUS_STATE_MAP.get(self.robot.status, STATE_ERROR)
@property @property