Skip to content

Commit 5960179

Browse files
Add food dispensed today and next feeding sensors to litterrobot (home-assistant#152016)
Co-authored-by: Abílio Costa <[email protected]>
1 parent 9f8f7d2 commit 5960179

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

homeassistant/components/litterrobot/icons.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
}
3737
},
3838
"sensor": {
39+
"food_dispensed_today": {
40+
"default": "mdi:counter"
41+
},
3942
"hopper_status": {
4043
"default": "mdi:filter",
4144
"state": {

homeassistant/components/litterrobot/sensor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ class RobotSensorEntityDescription(SensorEntityDescription, Generic[_WhiskerEnti
163163
),
164164
],
165165
FeederRobot: [
166+
RobotSensorEntityDescription[FeederRobot](
167+
key="food_dispensed_today",
168+
translation_key="food_dispensed_today",
169+
state_class=SensorStateClass.TOTAL,
170+
last_reset_fn=dt_util.start_of_local_day,
171+
value_fn=(
172+
lambda robot: (
173+
robot.get_food_dispensed_since(dt_util.start_of_local_day())
174+
)
175+
),
176+
),
166177
RobotSensorEntityDescription[FeederRobot](
167178
key="food_level",
168179
translation_key="food_level",
@@ -181,6 +192,12 @@ class RobotSensorEntityDescription(SensorEntityDescription, Generic[_WhiskerEnti
181192
)
182193
),
183194
),
195+
RobotSensorEntityDescription[FeederRobot](
196+
key="next_feeding",
197+
translation_key="next_feeding",
198+
device_class=SensorDeviceClass.TIMESTAMP,
199+
value_fn=lambda robot: robot.next_feeding,
200+
),
184201
],
185202
}
186203

homeassistant/components/litterrobot/strings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
}
6060
},
6161
"sensor": {
62+
"food_dispensed_today": {
63+
"name": "Food dispensed today",
64+
"unit_of_measurement": "cups"
65+
},
6266
"food_level": {
6367
"name": "Food level"
6468
},
@@ -82,6 +86,9 @@
8286
"litter_level": {
8387
"name": "Litter level"
8488
},
89+
"next_feeding": {
90+
"name": "Next feeding"
91+
},
8592
"pet_weight": {
8693
"name": "Pet weight"
8794
},

tests/components/litterrobot/common.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@
128128
"mealInsertSize": 1,
129129
},
130130
"updated_at": "2022-09-08T15:07:00.000000+00:00",
131+
"active_schedule": {
132+
"id": "1",
133+
"name": "Feeding",
134+
"meals": [
135+
{
136+
"id": "1",
137+
"days": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
138+
"hour": 6,
139+
"name": "Breakfast",
140+
"skip": None,
141+
"minute": 30,
142+
"paused": False,
143+
"portions": 3,
144+
"mealNumber": 1,
145+
"scheduleId": None,
146+
}
147+
],
148+
"created_at": "2021-12-17T07:07:31.047747+00:00",
149+
},
131150
},
132151
"feeding_snack": [
133152
{"timestamp": "2022-09-04T03:03:00.000000+00:00", "amount": 0.125},

tests/components/litterrobot/test_sensor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ async def test_litter_robot_sensor(
104104
assert sensor.attributes["state_class"] == SensorStateClass.TOTAL_INCREASING
105105

106106

107+
@pytest.mark.freeze_time("2022-09-08 19:00:00+00:00")
107108
async def test_feeder_robot_sensor(
108109
hass: HomeAssistant, mock_account_with_feederrobot: MagicMock
109110
) -> None:
@@ -117,6 +118,16 @@ async def test_feeder_robot_sensor(
117118
assert sensor.state == "2022-09-08T18:00:00+00:00"
118119
assert sensor.attributes["device_class"] == SensorDeviceClass.TIMESTAMP
119120

121+
sensor = hass.states.get("sensor.test_next_feeding")
122+
assert sensor.state == "2022-09-09T12:30:00+00:00"
123+
assert sensor.attributes["device_class"] == SensorDeviceClass.TIMESTAMP
124+
125+
sensor = hass.states.get("sensor.test_food_dispensed_today")
126+
assert sensor.state == "0.375"
127+
assert sensor.attributes["last_reset"] == "2022-09-08T00:00:00-07:00"
128+
assert sensor.attributes["state_class"] == SensorStateClass.TOTAL
129+
assert sensor.attributes["unit_of_measurement"] == "cups"
130+
120131

121132
async def test_pet_weight_sensor(
122133
hass: HomeAssistant, mock_account_with_pet: MagicMock

0 commit comments

Comments
 (0)