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

fix: message protocol version default #316

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(
self._device_protocol_version = device_protocol
self._model = model
self._subtype = subtype
self._message_protocol_version: ProtocolVersion = ProtocolVersion.V1
self._message_protocol_version: int = 0
self._updates: list[Callable[[dict[str, Any]], None]] = []
self._unsupported_protocol: list[str] = []
self._is_run = False
Expand Down
16 changes: 8 additions & 8 deletions midealocal/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import IntEnum
from typing import Generic, SupportsIndex, TypeVar, cast

from midealocal.const import DeviceType, ProtocolVersion
from midealocal.const import DeviceType

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,7 +132,7 @@ def __init__(self) -> None:
self._device_type: DeviceType = DeviceType.X00
self._message_type: MessageType = MessageType.default
self._body_type: BodyType = BodyType.X00
self._message_protocol_version: ProtocolVersion = ProtocolVersion.V1
self._message_protocol_version: int = 0

@staticmethod
def checksum(data: bytes) -> SupportsIndex:
Expand Down Expand Up @@ -177,12 +177,12 @@ def body_type(self, value: BodyType) -> None:
self._body_type = value

@property
def protocol_version(self) -> ProtocolVersion:
def protocol_version(self) -> int:
"""Message protocol version."""
return self._message_protocol_version

@protocol_version.setter
def protocol_version(self, protocol_version: ProtocolVersion) -> None:
def protocol_version(self, protocol_version: int) -> None:
self._message_protocol_version = protocol_version

def _format_attribute(
Expand Down Expand Up @@ -233,7 +233,7 @@ class MessageRequest(MessageBase):
def __init__(
self,
device_type: DeviceType,
protocol_version: ProtocolVersion,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
) -> None:
Expand Down Expand Up @@ -299,7 +299,7 @@ class MessageQuestCustom(MessageRequest):
def __init__(
self,
device_type: DeviceType,
protocol_version: ProtocolVersion,
protocol_version: int,
cmd_type: MessageType,
cmd_body: bytearray,
) -> None:
Expand Down Expand Up @@ -329,7 +329,7 @@ def __init__(self, device_type: DeviceType) -> None:
"""Initialize message query appliance."""
super().__init__(
device_type=device_type,
protocol_version=ProtocolVersion.V1,
protocol_version=0,
message_type=MessageType.query_appliance,
body_type=BodyType.X00,
)
Expand Down Expand Up @@ -573,7 +573,7 @@ def __init__(self, message: bytearray) -> None:
if message is None or len(message) < self.HEADER_LENGTH + 1:
raise MessageLenError
self._header = message[: self.HEADER_LENGTH]
self.protocol_version = ProtocolVersion(self._header[-2])
self.protocol_version = self._header[-2]
self.message_type = MessageType(self._header[-1])
self.device_type = DeviceType(self._header[2])
body = message[self.HEADER_LENGTH : -1]
Expand Down
Loading