mirror of
https://github.com/sudoxnym/roomba_rest980.git
synced 2026-04-14 11:37:46 +00:00
check if active mission, otherwise dont show start/elapsed time
This commit is contained in:
parent
cad8af474b
commit
d310a8441f
3 changed files with 43 additions and 27 deletions
|
|
@ -31,6 +31,20 @@ class RoombaSensor(CoordinatorEntity, SensorEntity):
|
||||||
"manufacturer": "iRobot",
|
"manufacturer": "iRobot",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def isMissionActive(self) -> bool:
|
||||||
|
"""Return whether or not there is a mission in progress."""
|
||||||
|
data = self.coordinator.data or {}
|
||||||
|
status = data.get("cleanMissionStatus", {})
|
||||||
|
# Mission State
|
||||||
|
phase = status.get("phase")
|
||||||
|
battery = data.get("batPct")
|
||||||
|
state = False
|
||||||
|
if status.get("mssnStrtTm"):
|
||||||
|
state = True
|
||||||
|
if phase == "charge" and battery == 100:
|
||||||
|
state = False
|
||||||
|
return state
|
||||||
|
|
||||||
def returnIn(self, mapping: dict[str, str], index: str) -> str:
|
def returnIn(self, mapping: dict[str, str], index: str) -> str:
|
||||||
"""Default or map value."""
|
"""Default or map value."""
|
||||||
mapping.get(index, index)
|
mapping.get(index, index)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@ia74"
|
"@ia74"
|
||||||
],
|
],
|
||||||
"version": "1.8.0",
|
"version": "1.9.0",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"dhcp": [
|
"dhcp": [
|
||||||
|
|
|
||||||
|
|
@ -286,16 +286,12 @@ class RoombaMissionStartTime(RoombaSensor):
|
||||||
|
|
||||||
def _handle_coordinator_update(self):
|
def _handle_coordinator_update(self):
|
||||||
"""Update sensor when coordinator data changes."""
|
"""Update sensor when coordinator data changes."""
|
||||||
data = self.coordinator.data or {}
|
if not self.isMissionActive():
|
||||||
status = data.get("cleanMissionStatus", {})
|
|
||||||
# Mission State
|
|
||||||
phase = status.get("phase")
|
|
||||||
battery = data.get("batPct")
|
|
||||||
|
|
||||||
if phase == "charge" and battery == 100:
|
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
self._attr_native_value = None
|
self._attr_native_value = None
|
||||||
else:
|
else:
|
||||||
|
data = self.coordinator.data or {}
|
||||||
|
status = data.get("cleanMissionStatus", {})
|
||||||
missionStartTime = status.get("mssnStrtTm") # Unix timestamp in seconds?
|
missionStartTime = status.get("mssnStrtTm") # Unix timestamp in seconds?
|
||||||
|
|
||||||
if missionStartTime:
|
if missionStartTime:
|
||||||
|
|
@ -327,23 +323,27 @@ class RoombaMissionElapsedTime(RoombaSensor):
|
||||||
|
|
||||||
def _handle_coordinator_update(self):
|
def _handle_coordinator_update(self):
|
||||||
"""Update sensor when coordinator data changes."""
|
"""Update sensor when coordinator data changes."""
|
||||||
data = self.coordinator.data or {}
|
if not self.isMissionActive():
|
||||||
status = data.get("cleanMissionStatus", {})
|
|
||||||
missionStartTime = status.get("mssnStrtTm") # Unix timestamp in seconds?
|
|
||||||
|
|
||||||
if missionStartTime:
|
|
||||||
self._attr_available = True
|
|
||||||
try:
|
|
||||||
elapsed_time = dt_util.utcnow() - dt_util.utc_from_timestamp(
|
|
||||||
missionStartTime
|
|
||||||
)
|
|
||||||
# Convert timedelta to minutes
|
|
||||||
self._attr_native_value = elapsed_time.total_seconds() / 60
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
self._attr_native_value = None
|
|
||||||
else:
|
|
||||||
self._attr_native_value = None
|
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
|
self._attr_native_value = None
|
||||||
|
else:
|
||||||
|
data = self.coordinator.data or {}
|
||||||
|
status = data.get("cleanMissionStatus", {})
|
||||||
|
missionStartTime = status.get("mssnStrtTm") # Unix timestamp in seconds?
|
||||||
|
|
||||||
|
if missionStartTime:
|
||||||
|
self._attr_available = True
|
||||||
|
try:
|
||||||
|
elapsed_time = dt_util.utcnow() - dt_util.utc_from_timestamp(
|
||||||
|
missionStartTime
|
||||||
|
)
|
||||||
|
# Convert timedelta to minutes
|
||||||
|
self._attr_native_value = elapsed_time.total_seconds() / 60
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._attr_native_value = None
|
||||||
|
else:
|
||||||
|
self._attr_native_value = None
|
||||||
|
self._attr_available = False
|
||||||
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
@ -363,12 +363,14 @@ class RoombaRechargeTime(RoombaSensor):
|
||||||
"""Update sensor when coordinator data changes."""
|
"""Update sensor when coordinator data changes."""
|
||||||
data = self.coordinator.data or {}
|
data = self.coordinator.data or {}
|
||||||
status = data.get("cleanMissionStatus", {})
|
status = data.get("cleanMissionStatus", {})
|
||||||
missionStartTime = status.get("rechrgTm") # Unix timestamp in seconds?
|
estimatedRechargeTime = status.get("rechrgTm") # Unix timestamp in seconds?
|
||||||
|
|
||||||
if missionStartTime:
|
if estimatedRechargeTime:
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
try:
|
try:
|
||||||
self._attr_native_value = dt_util.utc_from_timestamp(missionStartTime)
|
self._attr_native_value = dt_util.utc_from_timestamp(
|
||||||
|
estimatedRechargeTime
|
||||||
|
)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
self._attr_native_value = None
|
self._attr_native_value = None
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue