Skip to content

Commit

Permalink
Remove fallback and return unsupported devices too (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Nov 25, 2024
1 parent 3b3c156 commit ec366b2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 244 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
matrix:
python-version:
- "3.12"
- "3.13"
steps:
- name: ⤵️ Checkout repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
- verifyNoGetLogger

default_language_version:
python: python3.12
python: python3.13

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def main():

devices_ = await api_client.get_devices()

bot = Device(devices_[0], authenticator)
bot = Device(devices_.mqtt[0], authenticator)

mqtt_config = create_mqtt_config(device_id=device_id, country=country)
mqtt = MqttClient(mqtt_config, authenticator)
Expand Down
40 changes: 32 additions & 8 deletions deebot_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import asyncio
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any

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


@dataclass(frozen=True)
class Devices:
"""Devices."""

mqtt: list[DeviceInfo]
xmpp: list[ApiDeviceInfo]
not_supported: list[ApiDeviceInfo]


class ApiClient:
"""Api client."""

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

return result

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

devices: list[DeviceInfo | ApiDeviceInfo] = []
mqtt: list[DeviceInfo] = []
xmpp: list[ApiDeviceInfo] = []
not_supported: list[ApiDeviceInfo] = []
for device in api_devices.values():
match device.get("company"):
case "eco-ng":
static_device_info = await get_static_device_info(device["class"])
devices.append(DeviceInfo(device, static_device_info))
if static_device_info := await get_static_device_info(
device["class"]
):
mqtt.append(DeviceInfo(device, static_device_info))
else:
_LOGGER.warning(
'Device class "%s" not recognized. Please add support for it: %s',
device["class"],
device,
)
not_supported.append(device)
case "eco-legacy":
devices.append(device)
xmpp.append(device)
case _:
_LOGGER.debug("Skipping device as it is not supported: %s", device)
_LOGGER.warning(
"Skipping device as it is not supported: %s", device
)
not_supported.append(device)

if not devices:
if not mqtt and not xmpp and not not_supported:
_LOGGER.warning("No devices returned by the api. Please check the logs.")

return devices
return Devices(mqtt, xmpp, not_supported)

async def get_product_iot_map(self) -> dict[str, Any]:
"""Get product iot map."""
Expand Down
10 changes: 2 additions & 8 deletions deebot_client/hardware/deebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
_LOGGER = get_logger(__name__)


FALLBACK = "fallback"

DEVICES: dict[str, StaticDeviceInfo] = {}


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


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

_LOGGER.info(
"No capabilities found for %s, therefore not all features are available. trying to use fallback...",
class_,
)
return DEVICES[FALLBACK]
return None
184 changes: 0 additions & 184 deletions deebot_client/hardware/deebot/fallback.py

This file was deleted.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Home Automation",
"Topic :: Software Development :: Libraries :: Python Modules",
]
Expand Down Expand Up @@ -133,7 +134,7 @@ max-args = 7


[tool.pylint.MAIN]
py-version = "3.12"
py-version = "3.13"
ignore = [
"tests",
]
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
create_rest_config as create_config_rest,
)
from deebot_client.event_bus import EventBus
from deebot_client.hardware.deebot import FALLBACK, get_static_device_info
from deebot_client.hardware.deebot import get_static_device_info
from deebot_client.models import (
ApiDeviceInfo,
Credentials,
Expand Down Expand Up @@ -127,7 +127,9 @@ async def test_mqtt_client(

@pytest.fixture
async def static_device_info() -> StaticDeviceInfo:
return await get_static_device_info(FALLBACK)
info = await get_static_device_info("yna5xi")
assert info is not None
return info


@pytest.fixture
Expand Down
Loading

0 comments on commit ec366b2

Please sign in to comment.