8000 Add cleaning statistics for tplink (#135784) · home-assistant/core@653ff47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 653ff47

Browse files
rytilahtisdb9696
andauthored
Add cleaning statistics for tpl 10000 ink (#135784)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
1 parent c7176f6 commit 653ff47

File tree

6 files changed

+497
-3
lines changed

6 files changed

+497
-3
lines changed

homeassistant/components/tplink/const.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
from typing import Final
66

7-
from homeassistant.const import Platform, UnitOfTemperature
7+
from kasa.smart.modules.clean import AreaUnit
8+
9+
from homeassistant.const import Platform, UnitOfArea, UnitOfTemperature
810

911
DOMAIN = "tplink"
1012

@@ -47,4 +49,6 @@
4749
UNIT_MAPPING = {
4850
"celsius": UnitOfTemperature.CELSIUS,
4951
"fahrenheit": UnitOfTemperature.FAHRENHEIT,
52+
AreaUnit.Sqm: UnitOfArea.SQUARE_METERS,
53+
AreaUnit.Sqft: UnitOfArea.SQUARE_FEET,
5054
}

homeassistant/components/tplink/sensor.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,50 @@ class TPLinkSensorEntityDescription(
124124
TPLinkSensorEntityDescription(
125125
key="alarm_source",
126126
),
127+
# Vacuum cleaning records
128+
TPLinkSensorEntityDescription(
129+
key="clean_time",
130+
device_class=SensorDeviceClass.DURATION,
131+
native_unit_of_measurement=UnitOfTime.SECONDS,
132+
suggested_unit_of_measurement=UnitOfTime.MINUTES,
133+
convert_fn=_TOTAL_SECONDS_METHOD_CALLER,
134+
),
135+
TPLinkSensorEntityDescription(
136+
key="clean_area",
137+
device_class=SensorDeviceClass.AREA,
138+
),
139+
TPLinkSensorEntityDescription(
140+
key="clean_progress",
141+
),
142+
TPLinkSensorEntityDescription(
143+
key="last_clean_time",
144+
device_class=SensorDeviceClass.DURATION,
145+
native_unit_of_measurement=UnitOfTime.SECONDS,
146+
suggested_unit_of_measurement=UnitOfTime.MINUTES,
147+
convert_fn=_TOTAL_SECONDS_METHOD_CALLER,
148+
),
149+
TPLinkSensorEntityDescription(
150+
key="last_clean_area",
151+
device_class=SensorDeviceClass.AREA,
152+
),
153+
TPLinkSensorEntityDescription(
154+
key="last_clean_timestamp",
155+
device_class=SensorDeviceClass.TIMESTAMP,
156+
),
157+
TPLinkSensorEntityDescription(
158+
key="total_clean_time",
159+
device_class=SensorDeviceClass.DURATION,
160+
native_unit_of_measurement=UnitOfTime.SECONDS,
161+
suggested_unit_of_measurement=UnitOfTime.MINUTES,
162+
convert_fn=_TOTAL_SECONDS_METHOD_CALLER,
163+
),
164+
TPLinkSensorEntityDescription(
165+
key="total_clean_area",
166+
device_class=SensorDeviceClass.AREA,
167+
),
168+
TPLinkSensorEntityDescription(
169+
key="total_clean_count",
170+
),
127171
TPLinkSensorEntityDescription(
128172
key="main_brush_remaining",
129173
device_class=SensorDeviceClass.DURATION,

homeassistant/components/tplink/strings.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,33 @@
217217
"alarm_source": {
218218
"name": "Alarm source"
219219
},
220+
"clean_area": {
221+
"name": "Cleaning area"
222+
},
223+
"clean_time": {
224+
"name": "Cleaning time"
225+
},
226+
"clean_progress": {
227+
"name": "Cleaning progress"
228+
},
229+
"total_clean_area": {
230+
"name": "Total cleaning area"
231+
},
232+
"total_clean_time": {
233+
"name": "Total cleaning time"
234+
},
235+
"total_clean_count": {
236+
"name": "Total cleaning count"
237+
},
238+
"last_clean_area": {
239+
"name": "Last cleaned area"
240+
},
241+
"last_clean_time": {
242+
"name": "Last cleaned time"
243+
},
244+
"last_clean_timestamp": {
245+
"name": "Last clean start"
246+
},
220247
"main_brush_remaining": {
221248
"name": "Main brush remaining"
222249
},

tests/components/tplink/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from kasa.interfaces import Fan, Light, LightEffect, LightState, Thermostat
1919
from kasa.smart.modules import Speaker
2020
from kasa.smart.modules.alarm import Alarm
21-
from kasa.smart.modules.clean import Clean, ErrorCode, Status
21+
from kasa.smart.modules.clean import AreaUnit, Clean, ErrorCode, Status
2222
from kasa.smartcam.modules.camera import LOCAL_STREAMING_PORT, Camera
2323
from syrupy import SnapshotAssertion
2424

@@ -60,7 +60,7 @@ def _load_feature_fixtures():
6060

6161

6262
FEATURES_FIXTURE = _load_feature_fixtures()
63-
FIXTURE_ENUM_TYPES = {"CleanErrorCode": ErrorCode}
63+
FIXTURE_ENUM_TYPES = {"CleanErrorCode": ErrorCode, "CleanAreaUnit": AreaUnit}
6464

6565

6666
async def setup_platform_for_device(
@@ -276,12 +276,17 @@ def _mocked_feature(
276276
if fixture := FEATURES_FIXTURE.get(id):
277277
# copy the fixture so tests do not interfere with each other
278278
fixture = dict(fixture)
279+
279280
if enum_type := fixture.get("enum_type"):
280281
val = FIXTURE_ENUM_TYPES[enum_type](fixture["value"])
281282
fixture["value"] = val
282283
if timedelta_type := fixture.get("timedelta_type"):
283284
fixture["value"] = timedelta(**{timedelta_type: fixture["value"]})
284285

286+
if unit_enum_type := fixture.get("unit_enum_type"):
287+
val = FIXTURE_ENUM_TYPES[unit_enum_type](fixture["unit"])
288+
fixture["unit"] = val
289+
285290
else:
286291
assert require_fixture is False, (
287292
f"No fixture defined for feature {id} and require_fixture is True"

tests/components/tplink/fixtures/features.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,61 @@
341341
"Connection 2"
342342
]
343343
},
344+
"clean_time": {
345+
"type": "Sensor",
346+
"category": "Info",
347+
"value": 12,
348+
"timedelta_type": "minutes"
349+
},
350+
"clean_area": {
351+
"type": "Sensor",
352+
"category": "Info",
353+
"value": 2,
354+
"unit": 1,
355+
"unit_enum_type": "CleanAreaUnit"
356+
},
357+
"clean_progress": {
358+
"type": "Sensor",
359+
"category": "Info",
360+
"value": 30,
361+
"unit": "%"
362+
},
363+
"total_clean_time": {
364+
"type": "Sensor",
365+
"category": "Debug",
366+
"value": 120,
367+
"timedelta_type": "minutes"
368+
},
369+
"total_clean_area": {
370+
"type": "Sensor",
371+
"category": "Debug",
372+
"value": 2,
373+
"unit": 1,
374+
"unit_enum_type": "CleanAreaUnit"
375+
},
376+
"last_clean_time": {
377+
"type": "Sensor",
378+
"category": "Debug",
379+
"value": 60,
380+
"timedelta_type": "minutes"
381+
},
382+
"last_clean_area": {
383+
"type": "Sensor",
384+
"category": "Debug",
385+
"value": 2,
386+
"unit": 1,
387+
"unit_enum_type": "CleanAreaUnit"
388+
},
389+
"last_clean_timestamp": {
390+
"type": "Sensor",
391+
"category": "Debug",
392+
"value": "2024-06-24 10:03:11.046643+01:00"
393+
},
394+
"total_clean_count": {
395+
"type": "Sensor",
396+
"category": "Debug",
397+
"value": 12
398+
},
344399
"alarm_volume": {
345400
"value": "normal",
346401
"type": "Choice",

0 commit comments

Comments
 (0)
0