Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db): add new attributes for db device #329

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 200 additions & 16 deletions midealocal/devices/db/__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

Check warning on line 5 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L5

Added line #L5 was not covered by tests

from midealocal.const import DeviceType, ProtocolVersion
from midealocal.device import MideaDevice
Expand All @@ -18,14 +18,164 @@

power = "power"
start = "start"
status = "status"
mode = "mode"
program = "program"
water_level = "water_level"
temperature = "temperature"
dehydration_speed = "dehydration_speed"
wash_time = "wash_time"
wash_time_value = "wash_time_value"
dehydration_time = "dehydration_time"
dehydration_time_value = "dehydration_time_value"
detergent = "detergent"
softener = "softener"

Check warning on line 32 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L21-L32

Added lines #L21 - L32 were not covered by tests
washing_data = "washing_data"
progress = "progress"
time_remaining = "time_remaining"
stains = "stains"
dirty_degree = "dirty_degree"

Check warning on line 37 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L36-L37

Added lines #L36 - L37 were not covered by tests


class MideaDBDevice(MideaDevice):
"""Midea DB device."""

_status: ClassVar[dict[int, str]] = {

Check warning on line 43 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L43

Added line #L43 was not covered by tests
0: "idle",
1: "standby",
2: "start",
3: "pause",
4: "end",
5: "fault",
6: "delay",
}

_mode: ClassVar[dict[int, str]] = {

Check warning on line 53 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L53

Added line #L53 was not covered by tests
0: "normal",
1: "factory_test",
2: "service",
3: "normal_continus",
}

_dehydration_speed: ClassVar[dict[int, str]] = {

Check warning on line 60 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L60

Added line #L60 was not covered by tests
0x00: "0",
0x01: "400",
0x02: "600",
0x03: "800",
0x04: "1000",
0x05: "1200",
0x06: "1400",
0x07: "1600",
0x08: "1300",
0xFF: "default",
}

_water_level: ClassVar[dict[int, str]] = {

Check warning on line 73 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L73

Added line #L73 was not covered by tests
0x01: "Low",
0x02: "Mid",
0x03: "High",
0x04: "4",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "translated" to a string: VeryHigh ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the origina value from lua script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please share the LUA script

0x05: "Auto",
0xFF: "default",
}

_program: ClassVar[dict[int, str]] = {

Check warning on line 82 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L82

Added line #L82 was not covered by tests
0x00: "cotton",
0x01: "eco",
0x02: "fast_wash",
0x03: "mixed_wash",
0x04: "fiber",
0x05: "wool",
0x06: "enzyme",
0x07: "ssp",
0x08: "sport_clothes",
0x09: "single_dehytration",
0x0A: "rinsing_dehydration",
0x0B: "big",
0x0C: "baby_clothes",
0x0D: "outdoor",
0x0E: "air_wash",
0x0F: "down_jacket",
0x10: "color",
0x11: "intelligent",
0x12: "quick_wash",
0x13: "kids",
0x14: "water_cotton",
0x15: "single_drying",
0x16: "single_drying",
0x17: "fast_wash_30",
0x18: "fast_wash_60",
0x19: "water_intelligent",
0x1A: "water_steep",
0x1B: "water_fast_wash_30",
0x1C: "shirt",
0x1D: "steep",
0x1E: "new_water_cotton",
0x1F: "water_mixed_wash",
0x20: "water_fiber",
0x21: "water_kids",
0x22: "water_underwear",
0x23: "specialist",
0x24: "water_eco",
0x25: "wash_drying_60",
0x26: "self_wash_5",
0x27: "fast_wash_min",
0x28: "mixed_wash_min",
0x29: "dehydration_min",
0x2A: "self_wash_min",
0x2B: "baby_clothes_min",
0x2C: "prevent_allergy",
0x2D: "cold_wash",
0x2E: "soft_wash",
0x2F: "remove_mite_wash",
0x30: "water_intense_wash",
0x31: "fast_dry",
0x32: "water_outdoor",
0x33: "spring_autumn_wash",
0x34: "summer_wash",
0x35: "winter_wash",
0x36: "jean",
0x37: "new_clothes_wash",
0x38: "silk",
0x39: "insight_wash",
0x3A: "fitness_clothes",
0x3B: "mink",
0x3C: "fresh_air",
0x3D: "bucket_dry",
0x3E: "jacket",
0x3F: "bath_towel",
0x40: "night_fresh_wash",
0x50: "water_fiber",
0x51: "diy0",
0x52: "diy2",
0x60: "heart_wash",
0x61: "water_cold_wash",
0x62: "water_prevent_allergy",
0x63: "water_remove_mite_wash",
0x64: "water_ssp",
0x65: "silk_wash",
0x66: "standard",
0x67: "green_wool",
0x68: "cook_wash",
0x69: "fresh_remove_wrinkle",
0x6A: "steam_sterilize_wash",
0x6B: "aromatherapy",
0x70: "sterilize_wash",
0xFE: "love",
0xFF: "default",
}

_temperature: ClassVar[dict[int, str]] = {

Check warning on line 168 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L168

Added line #L168 was not covered by tests
0x01: "0",
0x02: "20",
0x03: "30",
0x04: "40",
0x05: "60",
0x06: "95",
0x07: "70",
wuwentao marked this conversation as resolved.
Show resolved Hide resolved
0xFF: "default",
}

def __init__(
self,
name: str,
Expand Down Expand Up @@ -54,9 +204,23 @@
attributes={
DeviceAttributes.power: False,
DeviceAttributes.start: False,
DeviceAttributes.status: None,
DeviceAttributes.mode: None,
DeviceAttributes.program: None,
DeviceAttributes.water_level: None,
DeviceAttributes.temperature: None,
DeviceAttributes.dehydration_speed: None,
DeviceAttributes.wash_time: None,
DeviceAttributes.dehydration_time: None,
DeviceAttributes.detergent: None,
DeviceAttributes.softener: None,
DeviceAttributes.washing_data: bytearray([]),
DeviceAttributes.progress: "Unknown",
DeviceAttributes.progress: None,
DeviceAttributes.stains: None,
DeviceAttributes.time_remaining: None,
DeviceAttributes.wash_time_value: None,
DeviceAttributes.dehydration_time_value: None,
DeviceAttributes.dirty_degree: None,
},
)

Expand All @@ -69,23 +233,43 @@
message = MessageDBResponse(msg)
_LOGGER.debug("[%s] Received: %s", self.device_id, message)
new_status = {}
progress = [
"Idle",
"Spin",
"Rinse",
"Wash",
"Pre-wash",
"Dry",
"Weight",
"Hi-speed Spin",
"Unknown",
]

for status in self._attributes:
if hasattr(message, str(status)):
if status == DeviceAttributes.progress:
self._attributes[status] = progress[getattr(message, str(status))]
value = getattr(message, str(status))

Check warning on line 239 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L239

Added line #L239 was not covered by tests
# parse mode
if status == DeviceAttributes.mode:
self._attributes[DeviceAttributes.mode] = MideaDBDevice._mode.get(

Check warning on line 242 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L241-L242

Added lines #L241 - L242 were not covered by tests
value,
value,
)
# parse status
elif status == DeviceAttributes.status:
self._attributes[DeviceAttributes.status] = (

Check warning on line 248 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L247-L248

Added lines #L247 - L248 were not covered by tests
MideaDBDevice._status.get(value, value)
)
# parse dehydration_speed
elif status == DeviceAttributes.dehydration_speed:
self._attributes[DeviceAttributes.dehydration_speed] = (

Check warning on line 253 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L252-L253

Added lines #L252 - L253 were not covered by tests
MideaDBDevice._dehydration_speed.get(value, value)
)
# parse water_level
elif status == DeviceAttributes.water_level:
self._attributes[DeviceAttributes.water_level] = (

Check warning on line 258 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L257-L258

Added lines #L257 - L258 were not covered by tests
MideaDBDevice._water_level.get(value, value)
)
# parse program
elif status == DeviceAttributes.program:
self._attributes[DeviceAttributes.program] = (

Check warning on line 263 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L262-L263

Added lines #L262 - L263 were not covered by tests
MideaDBDevice._program.get(value, value)
)
# parse temperature
elif status == DeviceAttributes.temperature:
self._attributes[DeviceAttributes.temperature] = (

Check warning on line 268 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L267-L268

Added lines #L267 - L268 were not covered by tests
MideaDBDevice._temperature.get(value, value)
)
else:
self._attributes[status] = getattr(message, str(status))
self._attributes[status] = value

Check warning on line 272 in midealocal/devices/db/__init__.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/__init__.py#L272

Added line #L272 was not covered by tests
new_status[str(status)] = self._attributes[status]
return new_status

Expand Down
20 changes: 15 additions & 5 deletions midealocal/devices/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@
self.power = body[1] > 0
self.start = body[2] in [2, 6]
self.washing_data = body[3:16]
self.progress = 0
self.status = body[2]
self.mode = body[3]
self.program = body[4]
self.water_level = body[5]
self.temperature = body[7]
self.dehydration_speed = body[8]
self.wash_time = body[9]
self.dehydration_time = body[10]
self.detergent = body[11]
self.softener = body[12]
self.progress = body[16]
self.stains = body[26]
self.wash_time_value = body[27]
self.dehydration_time_value = body[28]
self.dirty_degree = body[30]

Check warning on line 137 in midealocal/devices/db/message.py

View check run for this annotation

Codecov / codecov/patch

midealocal/devices/db/message.py#L123-L137

Added lines #L123 - L137 were not covered by tests
self.time_remaining: float | None = None
for i in range(7):
if (body[16] & (1 << i)) > 0:
self.progress = i + 1
break
if self.power:
self.time_remaining = body[17] + (body[18] << 8)

Expand Down
Loading