Skip to content

Commit

Permalink
Fix handling unknown device (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffSteinbok authored Oct 12, 2024
1 parent 40ec374 commit 4b4f119
Show file tree
Hide file tree
Showing 5 changed files with 642 additions and 4 deletions.
4 changes: 4 additions & 0 deletions custom_components/dreo/pydreo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ def _process_devices(self, dev_list: list) -> bool:
# If device_details is None at this point, we have an unknown device model.
# Unsupported/Unknown Device. Load the state, but store it in an "unsupported objects"
# list for later use in diagnostics.
device_class = None

if device_details is not None:
device_class = _DREO_DEVICE_TYPE_TO_CLASS.get(device_details.device_type, None)
else:
device_details = DreoDeviceDetails(device_type = DreoDeviceType.UNKNOWN)

if device_class is None:
device_class = PyDreoUnknownDevice
Expand Down
7 changes: 3 additions & 4 deletions custom_components/dreo/pydreo/pydreounknowndevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from typing import TYPE_CHECKING, Dict

from .constant import (
LOGGER_NAME,
DreoDeviceType
LOGGER_NAME
)

from .pydreobasedevice import PyDreoBaseDevice
Expand All @@ -19,6 +18,6 @@
class PyDreoUnknownDevice(PyDreoBaseDevice):
"""Dreo Device class for unknown devices."""

def __init__(self, details: Dict[str, list], dreo: "PyDreo"):
def __init__(self, device_definition: DreoDeviceDetails, details: Dict[str, list], dreo: "PyDreo"): #pylint: disable=useless-super-delegation
"""Initialize the Dreo Device."""
super().__init__(DreoDeviceDetails(device_type = DreoDeviceType.UNKNOWN), details, dreo)
super().__init__(device_definition, details, dreo)
99 changes: 99 additions & 0 deletions tests/pydreo/api_responses/get_device_state_UNKNOWN_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"code": 0,
"msg": "OK",
"data": {
"mixed": {
"mcu_hardware_model": {
"state": "SC95F8613B/EU",
"timestamp": 1724748442
},
"wifi_ssid": "**REDACTED**",
"windlevel": {
"state": 4,
"timestamp": 1724759313
},
"wifi_rssi": {
"state": -30,
"timestamp": 1724748442
},
"poweron": {
"state": true,
"timestamp": 1724782631
},
"tempunit": {
"state": 1,
"timestamp": 1724748442
},
"timeron": {
"state": {
"du": 0,
"ts": 1724748442
},
"timestamp": null
},
"module_firmware_version": {
"state": "1.2.15",
"timestamp": 1724748442
},
"mode": {
"state": 1,
"timestamp": 1724748442
},
"mcuon": {
"state": true,
"timestamp": 1724748442
},
"connected": {
"state": true,
"timestamp": 1724748442
},
"timeroff": {
"state": {
"du": 0,
"ts": 1724748442
},
"timestamp": null
},
"network_latency": {
"state": 90,
"timestamp": 1724748442
},
"module_hardware_model": {
"state": "PAI-051",
"timestamp": 1724748442
},
"mcu_firmware_version": {
"state": "1.0.8",
"timestamp": 1724748442
},
"customconf": {
"state": "temp:11111222222333333444444",
"timestamp": 1724748442
},
"ledkepton": {
"state": false,
"timestamp": 1724748442
},
"temperature": {
"state": 81,
"timestamp": 1724778379
},
"module_hardware_mac": "**REDACTED**",
"childlockon": {
"state": false,
"timestamp": 1724748442
},
"muteon": {
"state": true,
"timestamp": 1724748442
},
"hoscon": {
"state": false,
"timestamp": 1724783181
}
},
"sn": "UNKNOWN_1",
"productId": "***REMOVED BY ME ***",
"region": "eu-central-1"
}
}
Loading

0 comments on commit 4b4f119

Please sign in to comment.