Skip to content

Commit ec366b2

Browse files
authored
Remove fallback and return unsupported devices too (#600)
1 parent 3b3c156 commit ec366b2

File tree

9 files changed

+49
-244
lines changed

9 files changed

+49
-244
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
matrix:
5151
python-version:
5252
- "3.12"
53+
- "3.13"
5354
steps:
5455
- name: ⤵️ Checkout repository
5556
uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ci:
77
- verifyNoGetLogger
88

99
default_language_version:
10-
python: python3.12
10+
python: python3.13
1111

1212
repos:
1313
- repo: https://github.com/astral-sh/ruff-pre-commit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def main():
4747

4848
devices_ = await api_client.get_devices()
4949

50-
bot = Device(devices_[0], authenticator)
50+
bot = Device(devices_.mqtt[0], authenticator)
5151

5252
mqtt_config = create_mqtt_config(device_id=device_id, country=country)
5353
mqtt = MqttClient(mqtt_config, authenticator)

deebot_client/api_client.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
from dataclasses import dataclass
67
from typing import TYPE_CHECKING, Any
78

89
from deebot_client.hardware.deebot import get_static_device_info
@@ -22,6 +23,15 @@
2223
_LOGGER = get_logger(__name__)
2324

2425

26+
@dataclass(frozen=True)
27+
class Devices:
28+
"""Devices."""
29+
30+
mqtt: list[DeviceInfo]
31+
xmpp: list[ApiDeviceInfo]
32+
not_supported: list[ApiDeviceInfo]
33+
34+
2535
class ApiClient:
2636
"""Api client."""
2737

@@ -46,7 +56,7 @@ async def _get_devices(self, path: str, command: str) -> dict[str, ApiDeviceInfo
4656

4757
return result
4858

49-
async def get_devices(self) -> list[DeviceInfo | ApiDeviceInfo]:
59+
async def get_devices(self) -> Devices:
5060
"""Get compatible devices."""
5161
try:
5262
async with asyncio.TaskGroup() as tg:
@@ -62,21 +72,35 @@ async def get_devices(self) -> list[DeviceInfo | ApiDeviceInfo]:
6272
api_devices = task_device_list.result()
6373
api_devices.update(task_global_device_list.result())
6474

65-
devices: list[DeviceInfo | ApiDeviceInfo] = []
75+
mqtt: list[DeviceInfo] = []
76+
xmpp: list[ApiDeviceInfo] = []
77+
not_supported: list[ApiDeviceInfo] = []
6678
for device in api_devices.values():
6779
match device.get("company"):
6880
case "eco-ng":
69-
static_device_info = await get_static_device_info(device["class"])
70-
devices.append(DeviceInfo(device, static_device_info))
81+
if static_device_info := await get_static_device_info(
82+
device["class"]
83+
):
84+
mqtt.append(DeviceInfo(device, static_device_info))
85+
else:
86+
_LOGGER.warning(
87+
'Device class "%s" not recognized. Please add support for it: %s',
88+
device["class"],
89+
device,
90+
)
91+
not_supported.append(device)
7192
case "eco-legacy":
72-
devices.append(device)
93+
xmpp.append(device)
7394
case _:
74-
_LOGGER.debug("Skipping device as it is not supported: %s", device)
95+
_LOGGER.warning(
96+
"Skipping device as it is not supported: %s", device
97+
)
98+
not_supported.append(device)
7599

76-
if not devices:
100+
if not mqtt and not xmpp and not not_supported:
77101
_LOGGER.warning("No devices returned by the api. Please check the logs.")
78102

79-
return devices
103+
return Devices(mqtt, xmpp, not_supported)
80104

81105
async def get_product_iot_map(self) -> dict[str, Any]:
82106
"""Get product iot map."""

deebot_client/hardware/deebot/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
_LOGGER = get_logger(__name__)
1818

1919

20-
FALLBACK = "fallback"
21-
2220
DEVICES: dict[str, StaticDeviceInfo] = {}
2321

2422

@@ -28,7 +26,7 @@ def _load() -> None:
2826
importlib.import_module(full_package_name)
2927

3028

31-
async def get_static_device_info(class_: str) -> StaticDeviceInfo:
29+
async def get_static_device_info(class_: str) -> StaticDeviceInfo | None:
3230
"""Get static device info for given class."""
3331
if not DEVICES:
3432
await asyncio.get_event_loop().run_in_executor(None, _load)
@@ -37,8 +35,4 @@ async def get_static_device_info(class_: str) -> StaticDeviceInfo:
3735
_LOGGER.debug("Capabilities found for %s", class_)
3836
return device
3937

40-
_LOGGER.info(
41-
"No capabilities found for %s, therefore not all features are available. trying to use fallback...",
42-
class_,
43-
)
44-
return DEVICES[FALLBACK]
38+
return None

deebot_client/hardware/deebot/fallback.py

Lines changed: 0 additions & 184 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ classifiers = [
1515
"Development Status :: 4 - Beta",
1616
"Intended Audience :: Developers",
1717
"Programming Language :: Python :: 3.12",
18+
"Programming Language :: Python :: 3.13",
1819
"Topic :: Home Automation",
1920
"Topic :: Software Development :: Libraries :: Python Modules",
2021
]
@@ -133,7 +134,7 @@ max-args = 7
133134

134135

135136
[tool.pylint.MAIN]
136-
py-version = "3.12"
137+
py-version = "3.13"
137138
ignore = [
138139
"tests",
139140
]

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
create_rest_config as create_config_rest,
1616
)
1717
from deebot_client.event_bus import EventBus
18-
from deebot_client.hardware.deebot import FALLBACK, get_static_device_info
18+
from deebot_client.hardware.deebot import get_static_device_info
1919
from deebot_client.models import (
2020
ApiDeviceInfo,
2121
Credentials,
@@ -127,7 +127,9 @@ async def test_mqtt_client(
127127

128128
@pytest.fixture
129129
async def static_device_info() -> StaticDeviceInfo:
130-
return await get_static_device_info(FALLBACK)
130+
info = await get_static_device_info("yna5xi")
131+
assert info is not None
132+
return info
131133

132134

133135
@pytest.fixture

0 commit comments

Comments
 (0)