Skip to content

Commit 54e5107

Browse files
authored
Add total cycles sensor for Litter-Robot (home-assistant#147435)
* Add total cycles sensor for Litter-Robot * Add translatable unit of measurement cycles
1 parent 657a068 commit 54e5107

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

homeassistant/components/litterrobot/icons.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
"motor_fault_short": "mdi:flash-off",
4747
"motor_ot_amps": "mdi:flash-alert"
4848
}
49+
},
50+
"total_cycles": {
51+
"default": "mdi:counter"
4952
}
5053
},
5154
"switch": {

homeassistant/components/litterrobot/sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ class RobotSensorEntityDescription(SensorEntityDescription, Generic[_WhiskerEnti
115115
lambda robot: status.lower() if (status := robot.status_code) else None
116116
),
117117
),
118+
RobotSensorEntityDescription[LitterRobot](
119+
key="total_cycles",
120+
translation_key="total_cycles",
121+
entity_category=EntityCategory.DIAGNOSTIC,
122+
entity_registry_enabled_default=False,
123+
state_class=SensorStateClass.TOTAL_INCREASING,
124+
value_fn=lambda robot: robot.cycle_count,
125+
),
118126
],
119127
LitterRobot4: [
120128
RobotSensorEntityDescription[LitterRobot4](

homeassistant/components/litterrobot/strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@
118118
"spf": "Pinch detect at startup"
119119
}
120120
},
121+
"total_cycles": {
122+
"name": "Total cycles",
123+
"unit_of_measurement": "cycles"
124+
},
121125
"waste_drawer": {
122126
"name": "Waste drawer"
123127
}

tests/components/litterrobot/test_sensor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
import pytest
66

77
from homeassistant.components.litterrobot.sensor import icon_for_gauge_level
8-
from homeassistant.components.sensor import DOMAIN as PLATFORM_DOMAIN, SensorDeviceClass
8+
from homeassistant.components.sensor import (
9+
DOMAIN as PLATFORM_DOMAIN,
10+
SensorDeviceClass,
11+
SensorStateClass,
12+
)
913
from homeassistant.const import PERCENTAGE, STATE_UNKNOWN, UnitOfMass
1014
from homeassistant.core import HomeAssistant
1115

@@ -70,6 +74,7 @@ async def test_gauge_icon() -> None:
7074

7175

7276
@pytest.mark.freeze_time("2022-09-18 23:00:44+00:00")
77+
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
7378
async def test_litter_robot_sensor(
7479
hass: HomeAssistant, mock_account_with_litterrobot_4: MagicMock
7580
) -> None:
@@ -94,6 +99,9 @@ async def test_litter_robot_sensor(
9499
sensor = hass.states.get("sensor.test_pet_weight")
95100
assert sensor.state == "12.0"
96101
assert sensor.attributes["unit_of_measurement"] == UnitOfMass.POUNDS
102+
sensor = hass.states.get("sensor.test_total_cycles")
103+
assert sensor.state == "158"
104+
assert sensor.attributes["state_class"] == SensorStateClass.TOTAL_INCREASING
97105

98106

99107
async def test_feeder_robot_sensor(

0 commit comments

Comments
 (0)