Skip to content

Commit

Permalink
feat(dc): add new attributes for exist dc device
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed Oct 16, 2024
1 parent ea90491 commit 330b9b5
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
107 changes: 105 additions & 2 deletions midealocal/devices/dc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from enum import StrEnum
from typing import Any
from typing import Any, ClassVar

from midealocal.const import DeviceType, ProtocolVersion
from midealocal.device import MideaDevice
Expand All @@ -18,6 +18,16 @@ class DeviceAttributes(StrEnum):

power = "power"
start = "start"
status = "status"
program = "program"
intensity = "intensity"
dryness_level = "dryness_level"
dry_temperature = "dry_temperature"
error_code = "error_code"
door_warn = "door_warn"
ai_switch = "ai_switch"
material = "material"
water_box = "water_box"
washing_data = "washing_data"
progress = "progress"
time_remaining = "time_remaining"
Expand All @@ -26,6 +36,71 @@ class DeviceAttributes(StrEnum):
class MideaDCDevice(MideaDevice):
"""Midea DC device."""

_status: ClassVar[dict[int, str]] = {
1: "standby",
2: "start",
3: "pause",
4: "end",
5: "prevent_wrinkle_end",
6: "delay_choosing",
7: "fault",
8: "delay",
9: "delay_pause",
}

_program: ClassVar[dict[int, str]] = {
0: "cotton",
1: "fiber",
2: "mixed_wash",
3: "jean",
4: "bedsheet",
5: "outdoor",
6: "down_jacket",
7: "plush",
8: "wool",
9: "dehumidify",
10: "cold_air_fresh_air",
11: "hot_air_dry",
12: "sport_clothes",
13: "underwear",
14: "baby_clothes",
15: "shirt",
16: "standard",
17: "quick_dry",
18: "fresh_air",
19: "low_temp_dry",
20: "eco_dry",
21: "quick_dry_30",
22: "towel",
23: "intelligent_dry",
24: "steam_care",
25: "big",
26: "fixed_time_dry",
27: "night_dry",
28: "bracket_dry",
29: "western_trouser",
30: "dehumidification",
31: "smart_dry",
32: "four_piece_suit",
33: "warm_clothes",
34: "quick_dry_20",
35: "steam_sterilize",
36: "enzyme",
37: "big_60",
38: "steam_no_iron",
39: "air_wash",
40: "bed_clothes",
41: "little_fast_dry",
42: "small_piece_dry",
43: "big_dry",
44: "wool_nurse",
45: "sun_quilt",
46: "fresh_remove_smell",
47: "bucket_self_clean",
48: "silk",
49: "sterilize",
}

def __init__(
self,
name: str,
Expand Down Expand Up @@ -54,6 +129,16 @@ def __init__(
attributes={
DeviceAttributes.power: False,
DeviceAttributes.start: False,
DeviceAttributes.status: "Unknown",
DeviceAttributes.program: "None",
DeviceAttributes.intensity: None,
DeviceAttributes.dryness_level: None,
DeviceAttributes.dry_temperature: None,
DeviceAttributes.error_code: None,
DeviceAttributes.door_warn: None,
DeviceAttributes.ai_switch: None,
DeviceAttributes.material: None,
DeviceAttributes.water_box: None,
DeviceAttributes.washing_data: bytearray([]),
DeviceAttributes.progress: "Unknown",
DeviceAttributes.time_remaining: None,
Expand Down Expand Up @@ -81,8 +166,26 @@ def process_message(self, msg: bytes) -> dict[str, Any]:
]
for status in self._attributes:
if hasattr(message, str(status)):
value = getattr(message, str(status))
# parse progress
if status == DeviceAttributes.progress:
self._attributes[status] = progress[getattr(message, str(status))]
self._attributes[status] = progress[value]
# parse status
elif status == DeviceAttributes.status:
if value in MideaDCDevice._status:
self._attributes[DeviceAttributes.status] = (
MideaDCDevice._status.get(value)
)
else:
self._attributes[DeviceAttributes.status] = None
# parse program
elif status == DeviceAttributes.program:
if value in MideaDCDevice._program:
self._attributes[DeviceAttributes.program] = (
MideaDCDevice._program.get(value)
)
else:
self._attributes[DeviceAttributes.program] = None
else:
self._attributes[status] = getattr(message, str(status))
new_status[str(status)] = self._attributes[status]
Expand Down
10 changes: 10 additions & 0 deletions midealocal/devices/dc/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def __init__(self, body: bytearray) -> None:
super().__init__(body)
self.power = body[1] > 0
self.start = body[2] in [2, 6]
self.status = body[2]
self.program = body[4]
self.intensity = body[9]
self.dryness_level = body[10]
self.dry_temperature = body[10]
self.error_code = body[24]
self.door_warn = body[25]
self.ai_switch = body[27]
self.material = body[28]
self.water_box = body[29]
self.washing_data = body[3:15]
self.progress = 0
self.time_remaining: float | None = None
Expand Down

0 comments on commit 330b9b5

Please sign in to comment.