Skip to content

Commit c3bab1f

Browse files
authored
Add downtime and uptime sensors for Husqvarna Automower (#140804)
* Add downtime and uptime sensors for Husqvarna Automower * add strings
1 parent e9cf4a2 commit c3bab1f

File tree

5 files changed

+150
-4
lines changed

5 files changed

+150
-4
lines changed

homeassistant/components/husqvarna_automower/sensor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@ class AutomowerSensorEntityDescription(SensorEntityDescription):
295295
exists_fn=lambda data: data.statistics.cutting_blade_usage_time is not None,
296296
value_fn=attrgetter("statistics.cutting_blade_usage_time"),
297297
),
298+
AutomowerSensorEntityDescription(
299+
key="downtime",
300+
translation_key="downtime",
301+
state_class=SensorStateClass.TOTAL,
302+
device_class=SensorDeviceClass.DURATION,
303+
entity_registry_enabled_default=False,
304+
native_unit_of_measurement=UnitOfTime.SECONDS,
305+
suggested_display_precision=0,
306+
suggested_unit_of_measurement=UnitOfTime.HOURS,
307+
exists_fn=lambda data: data.statistics.downtime is not None,
308+
value_fn=attrgetter("statistics.downtime"),
309+
),
298310
AutomowerSensorEntityDescription(
299311
key="total_charging_time",
300312
translation_key="total_charging_time",
@@ -367,6 +379,18 @@ class AutomowerSensorEntityDescription(SensorEntityDescription):
367379
exists_fn=lambda data: data.statistics.total_drive_distance is not None,
368380
value_fn=attrgetter("statistics.total_drive_distance"),
369381
),
382+
AutomowerSensorEntityDescription(
383+
key="uptime",
384+
translation_key="uptime",
385+
state_class=SensorStateClass.TOTAL,
386+
device_class=SensorDeviceClass.DURATION,
387+
entity_registry_enabled_default=False,
388+
native_unit_of_measurement=UnitOfTime.SECONDS,
389+
suggested_display_precision=0,
390+
suggested_unit_of_measurement=UnitOfTime.HOURS,
391+
exists_fn=lambda data: data.statistics.uptime is not None,
392+
value_fn=attrgetter("statistics.uptime"),
393+
),
370394
AutomowerSensorEntityDescription(
371395
key="next_start_timestamp",
372396
translation_key="next_start_timestamp",

homeassistant/components/husqvarna_automower/strings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@
221221
"cutting_blade_usage_time": {
222222
"name": "Cutting blade usage time"
223223
},
224+
"downtime": {
225+
"name": "Downtime"
226+
},
224227
"restricted_reason": {
225228
"name": "Restricted reason",
226229
"state": {
@@ -263,6 +266,9 @@
263266
"demo": "Demo"
264267
}
265268
},
269+
"uptime": {
270+
"name": "Uptime"
271+
},
266272
"work_area": {
267273
"name": "Work area",
268274
"state": {

tests/components/husqvarna_automower/fixtures/mower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@
176176
],
177177
"statistics": {
178178
"cuttingBladeUsageTime": 123,
179-
"downTime": 123,
179+
"downTime": 3600,
180180
"numberOfChargingCycles": 1380,
181181
"numberOfCollisions": 11396,
182182
"totalChargingTime": 4334400,
183183
"totalCuttingTime": 4194000,
184184
"totalDriveDistance": 1780272,
185185
"totalRunningTime": 4564800,
186186
"totalSearchingTime": 370800,
187-
"upTime": 456
187+
"upTime": 7200
188188
},
189189
"stayOutZones": {
190190
"dirty": false,

tests/components/husqvarna_automower/snapshots/test_diagnostics.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@
9595
}),
9696
'statistics': dict({
9797
'cutting_blade_usage_time': 123,
98-
'downtime': 123,
98+
'downtime': 3600,
9999
'number_of_charging_cycles': 1380,
100100
'number_of_collisions': 11396,
101101
'total_charging_time': 4334400,
102102
'total_cutting_time': 4194000,
103103
'total_drive_distance': 1780272,
104104
'total_running_time': 4564800,
105105
'total_searching_time': 370800,
106-
'uptime': 456,
106+
'uptime': 7200,
107107
}),
108108
'stay_out_zones': dict({
109109
'dirty': False,

tests/components/husqvarna_automower/snapshots/test_sensor.ambr

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,64 @@
106106
'state': '0.034',
107107
})
108108
# ---
109+
# name: test_sensor_snapshot[sensor.test_mower_1_downtime-entry]
110+
EntityRegistryEntrySnapshot({
111+
'aliases': set({
112+
}),
113+
'area_id': None,
114+
'capabilities': dict({
115+
'state_class': <SensorStateClass.TOTAL: 'total'>,
116+
}),
117+
'config_entry_id': <ANY>,
118+
'config_subentry_id': <ANY>,
119+
'device_class': None,
120+
'device_id': <ANY>,
121+
'disabled_by': None,
122+
'domain': 'sensor',
123+
'entity_category': None,
124+
'entity_id': 'sensor.test_mower_1_downtime',
125+
'has_entity_name': True,
126+
'hidden_by': None,
127+
'icon': None,
128+
'id': <ANY>,
129+
'labels': set({
130+
}),
131+
'name': None,
132+
'options': dict({
133+
'sensor': dict({
134+
'suggested_display_precision': 0,
135+
}),
136+
'sensor.private': dict({
137+
'suggested_unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
138+
}),
139+
}),
140+
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
141+
'original_icon': None,
142+
'original_name': 'Downtime',
143+
'platform': 'husqvarna_automower',
144+
'previous_unique_id': None,
145+
'supported_features': 0,
146+
'translation_key': 'downtime',
147+
'unique_id': 'c7233734-b219-4287-a173-08e3643f89f0_downtime',
148+
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
149+
})
150+
# ---
151+
# name: test_sensor_snapshot[sensor.test_mower_1_downtime-state]
152+
StateSnapshot({
153+
'attributes': ReadOnlyDict({
154+
'device_class': 'duration',
155+
'friendly_name': 'Test Mower 1 Downtime',
156+
'state_class': <SensorStateClass.TOTAL: 'total'>,
157+
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
158+
}),
159+
'context': <ANY>,
160+
'entity_id': 'sensor.test_mower_1_downtime',
161+
'last_changed': <ANY>,
162+
'last_reported': <ANY>,
163+
'last_updated': <ANY>,
164+
'state': '1.0',
165+
})
166+
# ---
109167
# name: test_sensor_snapshot[sensor.test_mower_1_error-entry]
110168
EntityRegistryEntrySnapshot({
111169
'aliases': set({
@@ -1208,6 +1266,64 @@
12081266
'state': '103.000',
12091267
})
12101268
# ---
1269+
# name: test_sensor_snapshot[sensor.test_mower_1_uptime-entry]
1270+
EntityRegistryEntrySnapshot({
1271+
'aliases': set({
1272+
}),
1273+
'area_id': None,
1274+
'capabilities': dict({
1275+
'state_class': <SensorStateClass.TOTAL: 'total'>,
1276+
}),
1277+
'config_entry_id': <ANY>,
1278+
'config_subentry_id': <ANY>,
1279+
'device_class': None,
1280+
'device_id': <ANY>,
1281+
'disabled_by': None,
1282+
'domain': 'sensor',
1283+
'entity_category': None,
1284+
'entity_id': 'sensor.test_mower_1_uptime',
1285+
'has_entity_name': True,
1286+
'hidden_by': None,
1287+
'icon': None,
1288+
'id': <ANY>,
1289+
'labels': set({
1290+
}),
1291+
'name': None,
1292+
'options': dict({
1293+
'sensor': dict({
1294+
'suggested_display_precision': 0,
1295+
}),
1296+
'sensor.private': dict({
1297+
'suggested_unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
1298+
}),
1299+
}),
1300+
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
1301+
'original_icon': None,
1302+
'original_name': 'Uptime',
1303+
'platform': 'husqvarna_automower',
1304+
'previous_unique_id': None,
1305+
'supported_features': 0,
1306+
'translation_key': 'uptime',
1307+
'unique_id': 'c7233734-b219-4287-a173-08e3643f89f0_uptime',
1308+
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
1309+
})
1310+
# ---
1311+
# name: test_sensor_snapshot[sensor.test_mower_1_uptime-state]
1312+
StateSnapshot({
1313+
'attributes': ReadOnlyDict({
1314+
'device_class': 'duration',
1315+
'friendly_name': 'Test Mower 1 Uptime',
1316+
'state_class': <SensorStateClass.TOTAL: 'total'>,
1317+
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
1318+
}),
1319+
'context': <ANY>,
1320+
'entity_id': 'sensor.test_mower_1_uptime',
1321+
'last_changed': <ANY>,
1322+
'last_reported': <ANY>,
1323+
'last_updated': <ANY>,
1324+
'state': '2.0',
1325+
})
1326+
# ---
12111327
# name: test_sensor_snapshot[sensor.test_mower_1_work_area-entry]
12121328
EntityRegistryEntrySnapshot({
12131329
'aliases': set({

0 commit comments

Comments
 (0)