Skip to content

Commit

Permalink
chore: rename var to clarify meaning (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 authored Oct 4, 2024
1 parent f603a04 commit 9e50cb8
Show file tree
Hide file tree
Showing 49 changed files with 208 additions and 208 deletions.
2 changes: 1 addition & 1 deletion library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def main() -> None:
port=first_device["port"],
token=token,
key=key,
protocol=first_device["protocol"],
device_protocol=first_device["protocol"],
model=first_device["model"],
subtype=0,
customize="",
Expand Down
4 changes: 2 additions & 2 deletions midealocal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def discover(self) -> list[MideaDevice]:
port=device["port"],
token=key["token"],
key=key["key"],
protocol=device["protocol"],
device_protocol=device["protocol"],
model=device["model"],
subtype=0,
customize="",
Expand Down Expand Up @@ -143,7 +143,7 @@ def message(self) -> None:
device_type=device_type,
ip_address="192.168.192.168",
port=6664,
protocol=ProtocolVersion.V2,
device_protocol=ProtocolVersion.V2,
model="0000",
token="",
key="",
Expand Down
18 changes: 9 additions & 9 deletions midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
attributes: dict,
Expand All @@ -94,10 +94,10 @@ def __init__(
self._device_name = name
self._device_id = device_id
self._device_type = device_type
self._protocol = protocol
self._device_protocol_version = device_protocol
self._model = model
self._subtype = subtype
self._protocol_version: ProtocolVersion = ProtocolVersion.V1
self._message_protocol_version: ProtocolVersion = ProtocolVersion.V1
self._updates: list[Callable[[dict[str, Any]], None]] = []
self._unsupported_protocol: list[str] = []
self._is_run = False
Expand Down Expand Up @@ -165,7 +165,7 @@ def connect(self, check_protocol: bool = False) -> bool:
)
self._socket.connect((self._ip_address, self._port))
_LOGGER.debug("[%s] Connected", self._device_id)
if self._protocol == ProtocolVersion.V3:
if self._device_protocol_version == ProtocolVersion.V3:
self.authenticate()
# 1. midea_ac_lan add device verify token with connect and auth
# 2. init connection, check_protocol
Expand Down Expand Up @@ -231,7 +231,7 @@ def authenticate(self) -> None:

def send_message(self, data: bytes, query: bool = False) -> None:
"""Send message."""
if self._protocol == ProtocolVersion.V3:
if self._device_protocol_version == ProtocolVersion.V3:
self.send_message_v3(data, msg_type=MSGTYPE_ENCRYPTED_REQUEST, query=query)
else:
self.send_message_v2(data, query=query)
Expand Down Expand Up @@ -389,18 +389,18 @@ def pre_process_message(self, msg: bytearray) -> bool:
message = MessageApplianceResponse(msg)
self._appliance_query = False
_LOGGER.debug("[%s] Appliance query Received: %s", self._device_id, message)
self._protocol_version = message.protocol_version
self._message_protocol_version = message.protocol_version
_LOGGER.debug(
"[%s] Device protocol version: %s",
self._device_id,
self._protocol_version,
self._message_protocol_version,
)
return False
return True

def parse_message(self, msg: bytes) -> MessageResult:
"""Parse message."""
if self._protocol == ProtocolVersion.V3:
if self._device_protocol_version == ProtocolVersion.V3:
messages, self._buffer = self._security.decode_8370(self._buffer + msg)
else:
messages, self._buffer = self.fetch_v2_message(self._buffer + msg)
Expand Down Expand Up @@ -482,7 +482,7 @@ def send_command(self, cmd_type: MessageType, cmd_body: bytearray) -> None:
"""Send command."""
cmd = MessageQuestCustom(
self._device_type,
self._protocol_version,
self._message_protocol_version,
cmd_type,
cmd_body,
)
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from importlib import import_module
from typing import cast

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


Expand All @@ -15,7 +15,7 @@ def device_selector(
port: int,
token: str,
key: str,
protocol: int,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str,
Expand All @@ -34,7 +34,7 @@ def device_selector(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
customize=customize,
Expand Down
10 changes: 5 additions & 5 deletions midealocal/devices/a1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str, # noqa: ARG002
Expand All @@ -72,7 +72,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand Down Expand Up @@ -109,12 +109,12 @@ def water_level_sets(self) -> list[str]:

def build_query(self) -> list[MessageQuery]:
"""Midea A1 device build query."""
return [MessageQuery(self._protocol_version)]
return [MessageQuery(self._message_protocol_version)]

def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea A1 device process message."""
message = MessageA1Response(bytearray(msg))
self._protocol_version = message.protocol_version
self._message_protocol_version = message.protocol_version
_LOGGER.debug("[%s] Received: %s", self.device_id, message)
new_status = {}
for status in self._attributes:
Expand Down Expand Up @@ -159,7 +159,7 @@ def process_message(self, msg: bytes) -> dict[str, Any]:

def make_message_set(self) -> MessageSet:
"""Midea A1 device make message set."""
message = MessageSet(self._protocol_version)
message = MessageSet(self._message_protocol_version)
message.power = self._attributes[DeviceAttributes.power]
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
message.child_lock = self._attributes[DeviceAttributes.child_lock]
Expand Down
36 changes: 18 additions & 18 deletions midealocal/devices/ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str,
Expand All @@ -97,7 +97,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand Down Expand Up @@ -168,21 +168,21 @@ def build_query(
"""Midea AC device build query."""
if self._used_subprotocol:
return [
MessageSubProtocolQuery(self._protocol_version, 0x10),
MessageSubProtocolQuery(self._protocol_version, 0x11),
MessageSubProtocolQuery(self._protocol_version, 0x30),
MessageSubProtocolQuery(self._message_protocol_version, 0x10),
MessageSubProtocolQuery(self._message_protocol_version, 0x11),
MessageSubProtocolQuery(self._message_protocol_version, 0x30),
]
return [
MessageQuery(self._protocol_version),
MessageNewProtocolQuery(self._protocol_version),
MessagePowerQuery(self._protocol_version),
MessageQuery(self._message_protocol_version),
MessageNewProtocolQuery(self._message_protocol_version),
MessagePowerQuery(self._message_protocol_version),
]

def capabilities_query(self) -> list:
"""Capabilities query message."""
return [
MessageCapabilitiesQuery(self._protocol_version, False),
MessageCapabilitiesQuery(self._protocol_version, True),
MessageCapabilitiesQuery(self._message_protocol_version, False),
MessageCapabilitiesQuery(self._message_protocol_version, True),
]

def process_message(self, msg: bytes) -> dict[str, Any]:
Expand Down Expand Up @@ -232,7 +232,7 @@ def process_message(self, msg: bytes) -> dict[str, Any]:

def make_message_set(self) -> MessageGeneralSet:
"""Midea AC device make message set."""
message = MessageGeneralSet(self._protocol_version)
message = MessageGeneralSet(self._message_protocol_version)
message.power = self._attributes[DeviceAttributes.power]
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
message.mode = self._attributes[DeviceAttributes.mode]
Expand All @@ -256,7 +256,7 @@ def make_message_set(self) -> MessageGeneralSet:

def make_subptotocol_message_set(self) -> MessageSubProtocolSet:
"""Midea AC device make subprotocol message set."""
message = MessageSubProtocolSet(self._protocol_version)
message = MessageSubProtocolSet(self._message_protocol_version)
message.power = self._attributes[DeviceAttributes.power]
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
message.aux_heating = self._attributes[DeviceAttributes.aux_heating]
Expand Down Expand Up @@ -305,19 +305,19 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
self._attributes[DeviceAttributes.prompt_tone] = value
self.update_all({DeviceAttributes.prompt_tone.value: value})
elif attr == DeviceAttributes.screen_display:
message = MessageToggleDisplay(self._protocol_version)
message = MessageToggleDisplay(self._message_protocol_version)
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
elif attr in [
DeviceAttributes.indirect_wind,
DeviceAttributes.breezeless,
DeviceAttributes.screen_display_alternate,
]:
message = MessageNewProtocolSet(self._protocol_version)
message = MessageNewProtocolSet(self._message_protocol_version)
setattr(message, str(attr), value)
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
elif attr == DeviceAttributes.fresh_air_power:
if self._fresh_air_version is not None:
message = MessageNewProtocolSet(self._protocol_version)
message = MessageNewProtocolSet(self._message_protocol_version)
setattr(
message,
str(self._fresh_air_version),
Expand All @@ -338,18 +338,18 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
self._attributes[DeviceAttributes.fresh_air_fan_speed],
]
)
message = MessageNewProtocolSet(self._protocol_version)
message = MessageNewProtocolSet(self._message_protocol_version)
setattr(message, str(self._fresh_air_version), fresh_air)
elif not value:
message = MessageNewProtocolSet(self._protocol_version)
message = MessageNewProtocolSet(self._message_protocol_version)
setattr(
message,
str(self._fresh_air_version),
[False, self._attributes[DeviceAttributes.fresh_air_fan_speed]],
)
elif attr == DeviceAttributes.fresh_air_fan_speed:
if self._fresh_air_version is not None:
message = MessageNewProtocolSet(self._protocol_version)
message = MessageNewProtocolSet(self._message_protocol_version)
fresh_air = (
[True, int(value)]
if int(value) > 0
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/b0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str, # noqa: ARG002
Expand All @@ -58,7 +58,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand All @@ -74,7 +74,7 @@ def __init__(

def build_query(self) -> list[MessageQuery01]:
"""B0 Midea device build query."""
return [MessageQuery01(self._protocol_version)]
return [MessageQuery01(self._message_protocol_version)]

def process_message(self, msg: bytes) -> dict:
"""B0 Midea device process message."""
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/b1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str, # noqa: ARG002
Expand All @@ -58,7 +58,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand All @@ -74,7 +74,7 @@ def __init__(

def build_query(self) -> list[MessageQuery]:
"""Midea B1 device build query."""
return [MessageQuery(self._protocol_version)]
return [MessageQuery(self._message_protocol_version)]

def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea B1 device process message."""
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/b3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str, # noqa: ARG002
Expand All @@ -72,7 +72,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__(

def build_query(self) -> list[MessageQuery]:
"""Midea local B3 device build query."""
return [MessageQuery(self._protocol_version)]
return [MessageQuery(self._message_protocol_version)]

def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea local B3 process message."""
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/b4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
port: int,
token: str,
key: str,
protocol: ProtocolVersion,
device_protocol: ProtocolVersion,
model: str,
subtype: int,
customize: str, # noqa: ARG002
Expand All @@ -58,7 +58,7 @@ def __init__(
port=port,
token=token,
key=key,
protocol=protocol,
device_protocol=device_protocol,
model=model,
subtype=subtype,
attributes={
Expand All @@ -74,7 +74,7 @@ def __init__(

def build_query(self) -> list[MessageQuery]:
"""Midea B4 device build query."""
return [MessageQuery(self._protocol_version)]
return [MessageQuery(self._message_protocol_version)]

def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea B4 device process message."""
Expand Down
Loading

0 comments on commit 9e50cb8

Please sign in to comment.