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

build: enable mypy #23

Merged
merged 1 commit into from
May 27, 2024
Merged
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
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ repos:
rev: v2.3.0
hooks:
- id: codespell
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.10.0
# hooks:
# - id: mypy
# additional_dependencies: []
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: []
4 changes: 3 additions & 1 deletion library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ async def main() -> None:
account=args.username,
password=args.password,
)
cloud_keys = await cloud.get_keys(first_device["device_id"])
cloud_keys = {}
if cloud:
cloud_keys = await cloud.get_keys(first_device["device_id"])
print("-" * 20)
print("Fist device Cloud info: ", cloud_keys)

Expand Down
29 changes: 15 additions & 14 deletions midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(
self._api_url = api_url
self._access_token = None
self._uid = None
self._login_id = None
self._login_id = ""

def _make_general_data(self):
return {}
Expand Down Expand Up @@ -289,15 +289,11 @@ async def list_appliances(self, home_id) -> dict | None:
"model": appliance.get("productModel"),
"online": appliance.get("onlineStatus") == "1",
}
if (
device_info.get("sn8") is None
or len(device_info.get("sn8")) == 0
):
sn8 = device_info.get("sn8")
if not sn8 or len(sn8) == 0:
device_info["sn8"] = "00000000"
if (
device_info.get("model") is None
or len(device_info.get("model")) == 0
):
model = device_info.get("model")
if not model or len(model) == 0:
device_info["model"] = device_info["sn8"]
appliances[int(appliance["applianceCode"])] = device_info
return appliances
Expand All @@ -312,9 +308,10 @@ async def get_device_info(self, device_id: int):
model_number = int(response.get("modelNumber", 0))
except ValueError:
model_number = 0
model_type = response.get("type")
device_info = {
"name": response.get("name"),
"type": int(response.get("type"), 16),
"type": int(model_type, 16) if model_type else 0,
"sn": (
self._security.aes_decrypt(response.get("sn"))
if response.get("sn")
Expand All @@ -326,9 +323,11 @@ async def get_device_info(self, device_id: int):
"model": response.get("productModel"),
"online": response.get("onlineStatus") == "1",
}
if device_info.get("sn8") is None or len(device_info.get("sn8")) == 0:
sn8 = device_info.get("sn8")
if sn8 is None or len(sn8) == 0:
device_info["sn8"] = "00000000"
if device_info.get("model") is None or len(device_info.get("model")) == 0:
model = device_info.get("model")
if model is None or len(model) == 0:
device_info["model"] = device_info["sn8"]
return device_info
return None
Expand Down Expand Up @@ -487,8 +486,9 @@ async def list_appliances(self, home_id) -> dict | None:
"model": "",
"online": appliance.get("onlineStatus") == "1",
}
serial_num = device_info.get("sn")
device_info["sn8"] = (
device_info.get("sn")[9:17] if len(device_info["sn"]) > 17 else ""
serial_num[9:17] if (serial_num and len(serial_num) > 17) else ""
)
device_info["model"] = device_info.get("sn8")
appliances[int(appliance["id"])] = device_info
Expand Down Expand Up @@ -645,8 +645,9 @@ async def list_appliances(self, home_id) -> dict | None:
"model": "",
"online": appliance.get("onlineStatus") == "1",
}
serial_num = device_info.get("sn")
device_info["sn8"] = (
device_info.get("sn")[9:17] if len(device_info["sn"]) > 17 else ""
serial_num[9:17] if (serial_num and len(serial_num) > 17) else ""
)
device_info["model"] = device_info.get("sn8")
appliances[int(appliance["id"])] = device_info
Expand Down
4 changes: 2 additions & 2 deletions midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __init__(
self._model = model
self._subtype = subtype
self._protocol_version = 0
self._updates = []
self._unsupported_protocol = []
self._updates = [dict]
self._unsupported_protocol = [dict]
self._is_run = False
self._available = True
self._appliance_query = True
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/a1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageA1Response, MessageSet

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
MessageSubProtocolSet,
)

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/b0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery01, MessageB0Response

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/b1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageB1Response

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/b3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageB3Response

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/b4/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageB4Response

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/b6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import json
from .message import MessageQuery, MessageB6Response, MessageSet

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/bf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageBFResponse

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/c2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import json
from .message import MessageQuery, MessageC2Response, MessageSet, MessagePower

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/c3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
MessageSet,
)

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/ca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageCAResponse

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/cc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageSet, MessageCCResponse

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
13 changes: 9 additions & 4 deletions midealocal/devices/cd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import logging
import json
from typing import Any
from .message import MessageQuery, MessageSet, MessageCDResponse

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum


from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +69,7 @@ def __init__(
DeviceAttributes.compressor_status: None,
},
)
self._fields = {}
self._fields = dict[Any, Any]
self._temperature_step = None
self._default_temperature_step = 1
self.set_customize(customize)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/ce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import json
from .message import MessageQuery, MessageCEResponse, MessageSet

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/cf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessageCFResponse, MessageSet

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions midealocal/devices/da/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from .message import MessageQuery, MessagePower, MessageStart, MessageDAResponse

try:
from enum import StrEnum
except ImportError:
import sys

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
else:
from enum import StrEnum

from ...device import MideaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down
Loading
Loading