8000 Convert to mashumaro, use kwargs for features · python-kasa/python-kasa@d806d98 · GitHub
[go: up one dir, main page]

Skip to content

Commit d806d98

Browse files
committed
Convert to mashumaro, use kwargs for features
1 parent 7cbbf24 commit d806d98

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

kasa/smart/modules/vacuumrecords.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
"""Implementation of vacuum records for experimental vacuum support."""
1+
"""Implementation of vacuum cleaning records."""
22

33
from __future__ import annotations
44

55
import logging
6+
from dataclasses import dataclass
67
from datetime import datetime
78

8-
from pydantic.v1 import BaseModel
9+
from mashumaro import DataClassDictMixin
910

1011
from ...feature import Feature
1112
from ..smartmodule import SmartModule
1213

1314
_LOGGER = logging.getLogger(__name__)
1415

1516

16-
class LatestRecord(BaseModel):
17+
@dataclass
18+
class LatestRecord(DataClassDictMixin):
1719
"""Stats from last clean.
1820
1921
TODO: this is just a list-formatted Record, with only some fields being available.
@@ -25,7 +27,8 @@ class LatestRecord(BaseModel):
2527
error: int # most likely
2628

2729

28-
class Record(BaseModel):
30+
@dataclass
31+
class Record(DataClassDictMixin):
2932
"""Historical cleanup result.
3033
3134
Example:
@@ -55,7 +58,8 @@ class Record(BaseModel):
5558
record_index: int
5659

5760

58-
class Records(BaseModel):
61+
@dataclass
62+
class Records(DataClassDictMixin):
5963
"""Response payload for getCleanRecords.
6064
6165
Example:
@@ -85,30 +89,30 @@ class Records(BaseModel):
8589

8690

8791
class VacuumRecords(SmartModule):
88-
"""Implementation of vacuum records for experimental vacuum support."""
92+
"""Implementation of vacuum cleaning records."""
8993

9094
REQUIRED_COMPONENT = "consumables"
9195
QUERY_GETTER_NAME = "getCleanRecords"
9296

93-
def _initialize_features(self):
97+
def _initialize_features(self) -> None:
9498
"""Initialize features."""
9599
self._add_feature(
96100
Feature(
97101
self._device,
98-
"total_clean_area",
99-
"Total area cleaned",
102+
id="total_clean_area",
103+
name="Total area cleaned",
100104
container=self,
101105
attribute_getter="total_clean_area",
102-
unit="sqm",
106+
unit_getter=lambda: "sqm",
103107
category=Feature.Category.Info,
104108
type=Feature.Type.Sensor,
105109
)
106110
)
107111
self._add_feature(
108112
Feature(
109113
self._device,
110-
"total_clean_time",
111-
"Total time cleaned",
114+
id="total_clean_time",
115+
name="Total time cleaned",
112116
container=self,
113117
attribute_getter="total_clean_time",
114118
category=Feature.Category.Info,
@@ -118,8 +122,8 @@ def _initialize_features(self):
118122
self._add_feature(
119123
Feature(
120124
self._device,
121-
"total_clean_count",
122-
"Total clean count",
125+
id="total_clean_count",
126+
name="Total clean count",
123127
container=self,
124128
attribute_getter="total_clean_count",
125129
category=Feature.Category.Debug,

0 commit comments

Comments
 (0)
0