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

增加 #419

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions custom_components/midea_ac_lan/midea/devices/db/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MessageQuery,
MessagePower,
MessageStart,
MessageDehytration,
MessageDBResponse
)
from ...core.device import MiedaDevice
Expand All @@ -17,6 +18,7 @@ class DeviceAttributes(StrEnum):
washing_data = "washing_data"
progress = "progress"
time_remaining = "time_remaining"
dehytration="dehytration"


class MideaDBDevice(MiedaDevice):
Expand Down Expand Up @@ -46,7 +48,10 @@ def __init__(
self._attributes = {
DeviceAttributes.power: False,
DeviceAttributes.start: False,
DeviceAttributes.washing_data: bytearray([]),
# DeviceAttributes.washing_data: bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00]),
DeviceAttributes.washing_data: bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF]),
DeviceAttributes.dehytration: False,

DeviceAttributes.progress: "Unknown",
DeviceAttributes.time_remaining: None
}
Expand All @@ -73,13 +78,25 @@ def set_attribute(self, attr, value):
if attr == DeviceAttributes.power:
message = MessagePower(self._device_protocol_version)
message.power = value

_LOGGER.debug(f"[{self.device_id}] power : {message}")

self.build_send(message)
elif attr == DeviceAttributes.start:
message = MessageStart(self._device_protocol_version)
message.start = value
message.washing_data = self._attributes[DeviceAttributes.washing_data]
self.build_send(message)

_LOGGER.debug(f"[{self.device_id}] start washing_data: {message}")

self.build_send(message)
elif attr == DeviceAttributes.dehytration:
message = MessageDehytration(self._device_protocol_version)
message.dehytration = value
message.washing_data = bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF])

_LOGGER.debug(f"[{self.device_id}] start washing_data: {message}")
self.build_send(message)

class MideaAppliance(MideaDBDevice):
pass
36 changes: 34 additions & 2 deletions custom_components/midea_ac_lan/midea/devices/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, device_protocol_version):
message_type=MessageType.set,
body_type=0x02)
self.start = False
self.washing_data = bytearray([])
self.washing_data = bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF])

@property
def _body(self):
Expand All @@ -74,13 +74,45 @@ def _body(self):
0xFF, 0x00
])

class MessageDehytration(MessageDBBase):
def __init__(self, device_protocol_version):
super().__init__(
device_protocol_version=device_protocol_version,
message_type=MessageType.set,
body_type=0x02)
self.dehytration = False
self.washing_data = bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF])

@property
def _body(self):
if self.dehytration: # Pause
return bytearray([
0xFF, 0x01
]) + self.washing_data
else:
# Pause
return bytearray([
0xFF, 0x00
])



class DBGeneralMessageBody(MessageBody):
def __init__(self, body):
super().__init__(body)
self.power = body[1] > 0
self.start = True if body[2] in [2, 6] else False
self.washing_data = body[3:16]

self.dehytration = True if body[2] in [2, 6] else False

# self.washing_data = body[3:16]
print("body start:")

print(body)
print("body end:")
Comment on lines +109 to +112

Choose a reason for hiding this comment

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

Please use _LOGGER.debug instead of print.


# self.washing_data=bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00])
# body[3:16]=bytearray([0x00,0x09,0xFF,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00])
self.progress = 0
for i in range(0, 7):
if (body[16] & (1 << i)) > 0:
Expand Down
8 changes: 7 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/e1/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MessageQuery,
MessagePower,
MessageStorage,
MessageStrongStart,
MessageLock,
MessageE1Response
)
Expand Down Expand Up @@ -31,6 +32,7 @@ class DeviceAttributes(StrEnum):
storage_remaining = "storage_remaining"
temperature = "temperature"
humidity = "humidity"
strong = "strong"


class MideaE1Device(MiedaDevice):
Expand Down Expand Up @@ -70,6 +72,7 @@ def __init__(
DeviceAttributes.salt: False,
DeviceAttributes.child_lock: False,
DeviceAttributes.storage: False,
DeviceAttributes.strong: False,
DeviceAttributes.storage_status: False,
DeviceAttributes.time_remaining: None,
DeviceAttributes.progress: None,
Expand Down Expand Up @@ -129,7 +132,10 @@ def set_attribute(self, attr, value):
message = MessageStorage(self._device_protocol_version)
message.storage = value
self.build_send(message)

elif attr == DeviceAttributes.strong:
message = MessageStrongStart(self._device_protocol_version)
message.strong = value
self.build_send(message)

class MideaAppliance(MideaE1Device):
pass
29 changes: 29 additions & 0 deletions custom_components/midea_ac_lan/midea/devices/e1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ def _body(self):
bytearray([0xff] * 6) + bytearray([0x00] * 27)


class MessageStrongStart(MessageE1Base):
def __init__(self, device_protocol_version):
super().__init__(
device_protocol_version=device_protocol_version,
message_type=MessageType.set,
body_type=0x08)
self.strong = False

@property
def _body(self):
strong = 0x03 if self.strong else 0x01
# return bytearray([0x00, 0x00, 0x00, strong]) + \
# bytearray([0xff] * 6) + bytearray([0x00] * 27)

# return bytearray([
# 0x03,0x02,0x00,0x00
# ])

return bytearray([
strong,0x02,0x00,0x00
])

class MessageQuery(MessageE1Base):
def __init__(self, device_protocol_version):
super().__init__(
Expand All @@ -82,6 +104,9 @@ class E1GeneralMessageBody(MessageBody):
def __init__(self, body):
super().__init__(body)
self.power = body[1] > 0

self.strong= body[1] > 2

self.status = body[1]
self.mode = body[2]
self.additional = body[3]
Expand All @@ -91,8 +116,11 @@ def __init__(self, body):
start_pause = (body[5] & 0x08) > 0
if start_pause:
self.start = True

elif self.status in [2, 3]:
self.start = False


self.child_lock = (body[5] & 0x10) > 0
self.uv = (body[4] & 0x2) > 0
self.dry = (body[4] & 0x10) > 0
Expand All @@ -110,6 +138,7 @@ class MessageE1Response(MessageResponse):
def __init__(self, message):
super().__init__(message)
body = message[10: -1]
print(body)

Choose a reason for hiding this comment

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

Here as well

if (self._message_type == MessageType.set and 0 <= self._body_type <= 7) or \
(self._message_type in [MessageType.query, MessageType.notify1] and self._body_type == 0):
self._body = E1GeneralMessageBody(body)
Expand Down
157 changes: 157 additions & 0 deletions custom_components/midea_ac_lan/midea/devices/f1/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import logging
from .message import (
MessageQuery,
MessageF1Response,
MessageSet
)
from ...core.device import MiedaDevice
from ...backports.enum import StrEnum

_LOGGER = logging.getLogger(__name__)


class DeviceAttributes(StrEnum):
mode="mode"
error_code="error_code"
response_type="response_type"
work_status="work_status"
step_status="step_status"
work_step="work_step"
cup_capstatus="cup_capstatus"
cup_bodystatus="cup_bodystatus"
curworktime="curworktime"
curtemperature="curtemperature"
curwork_speed="curwork_speed"
temperature_reservehot="temperature_reservehot"
temperature_reservewarm="temperature_reservewarm"
time_reservefinish="time_reservefinish"
time_reservework="time_reservework"
time_reservewarm="time_reservewarm"
code_id="code_id"


class MideaF1Device(MiedaDevice):

def __init__(
self,
name: str,
device_id: int,
ip_address: str,
port: int,
token: str,
key: str,
protocol: int,
model: str,
customize: str
):
super().__init__(
name=name,
device_id=device_id,
device_type=0xF1,
ip_address=ip_address,
port=port,
token=token,
key=key,
protocol=protocol,
model=model
)
self._attributes = {
DeviceAttributes.mode: None,
DeviceAttributes.error_code: None,
DeviceAttributes.response_type: None,
DeviceAttributes.work_status: None,
DeviceAttributes.step_status: None,
DeviceAttributes.work_step: None,
DeviceAttributes.cup_capstatus: None,
DeviceAttributes.cup_bodystatus: None,
DeviceAttributes.curworktime: None,
DeviceAttributes.curtemperature: None,
DeviceAttributes.curwork_speed: None,
DeviceAttributes.temperature_reservehot: None,
DeviceAttributes.temperature_reservewarm: None,
DeviceAttributes.time_reservefinish: None,
DeviceAttributes.time_reservework: None,
DeviceAttributes.time_reservewarm: None,
DeviceAttributes.code_id: None
}

# @property
# def modes(self):
# return MideaF1Device._modes

# @property
# def fan_speeds(self):
# return list(MideaF1Device._speeds.values())

# @property
# def water_level_sets(self):
# return MideaF1Device._water_level_sets

def build_query(self):
return [
MessageQuery(self._device_protocol_version)
]

def process_message(self, msg):
message = MessageF1Response(msg)
_LOGGER.debug(f"[{self.device_id}] Received: {message}")
new_status = {}
for status in self._attributes.keys():
if hasattr(message, status.value):
self._attributes[status] = getattr(message, status.value)
new_status[status.value] = getattr(message, status.value)
return new_status

def make_message_set(self):
message = MessageSet(self._device_protocol_version)
message.mode = self._attributes[DeviceAttributes.mode]
message.error_code = self._attributes[DeviceAttributes.error_code]
message.response_type = self._attributes[DeviceAttributes.response_type]
message.work_status = self._attributes[DeviceAttributes.work_status]
message.step_status = self._attributes[DeviceAttributes.step_status]
message.work_step = self._attributes[DeviceAttributes.work_step]
message.cup_capstatus = self._attributes[DeviceAttributes.cup_capstatus]
message.cup_bodystatus = self._attributes[DeviceAttributes.cup_bodystatus]
message.curworktime = self._attributes[DeviceAttributes.curworktime]
message.curtemperature = self._attributes[DeviceAttributes.curtemperature]
message.curwork_speed = self._attributes[DeviceAttributes.curwork_speed]
message.temperature_reservehot = self._attributes[DeviceAttributes.temperature_reservehot]
message.temperature_reservewarm = self._attributes[DeviceAttributes.temperature_reservewarm]
message.time_reservefinish = self._attributes[DeviceAttributes.time_reservefinish]
message.time_reservework = self._attributes[DeviceAttributes.time_reservework]
message.time_reservewarm = self._attributes[DeviceAttributes.time_reservewarm]
message.code_id = self._attributes[DeviceAttributes.code_id]

return message


def set_attribute(self, attr, value):
# if attr == DeviceAttributes.prompt_tone:
# self._attributes[DeviceAttributes.prompt_tone] = value
# self.update_all({DeviceAttributes.prompt_tone.value: value})
# else:
# message = self.make_message_set()
# if attr == DeviceAttributes.mode:
# if value in MideaF1Device._modes:
# message.mode = MideaF1Device._modes.index(value) + 1
# elif attr == DeviceAttributes.fan_speed:
# if value in MideaF1Device._speeds.values():
# message.fan_speed = list(MideaF1Device._speeds.keys())[
# list(MideaF1Device._speeds.values()).index(value)
# ]
# elif attr == DeviceAttributes.water_level_set:
# if value in MideaF1Device._water_level_sets:
# message.water_level_set = int(value)
# else:
message = self.make_message_set()

setattr(message, str(attr), value)
self.build_send(message)

@property
def attributes(self):
return super().attributes


class MideaAppliance(MideaF1Device):
pass
Loading