Skip to content

Commit 9b7bca0

Browse files
authored
Update device model (#302)
* Update model * Update model * Catch unknown enums
1 parent 326945a commit 9b7bca0

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pyoverkiz/enums/ui.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import logging
12
from enum import Enum, unique
23

4+
_LOGGER = logging.getLogger(__name__)
5+
36

47
@unique
58
class UIClass(str, Enum):
@@ -70,6 +73,13 @@ class UIClass(str, Enum):
7073
WINDOW = "Window"
7174
WINDOW_HANDLE = "WindowHandle"
7275

76+
UNKNOWN = "unknown"
77+
78+
@classmethod
79+
def _missing_(cls, value): # type: ignore
80+
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
81+
return cls.UNKNOWN
82+
7383

7484
@unique
7585
class UIWidget(str, Enum):
@@ -394,3 +404,10 @@ class UIWidget(str, Enum):
394404
ZWAVE_TRANSCEIVER = "ZWaveTransceiver"
395405
ZIGBEE_NETWORK = "ZigbeeNetwork"
396406
ZIGBEE_STACK = "ZigbeeStack"
407+
408+
UNKNOWN = "unknown"
409+
410+
@classmethod
411+
def _missing_(cls, value): # type: ignore
412+
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
413+
return cls.UNKNOWN

pyoverkiz/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
GatewaySubType,
1616
GatewayType,
1717
ProductType,
18+
UIClass,
19+
UIWidget,
1820
UpdateBoxStatus,
1921
)
2022

@@ -151,8 +153,8 @@ class Device:
151153
controllable_name: str
152154
definition: Definition
153155
data_properties: list[dict[str, Any]] | None = None
154-
widget: str | None = None
155-
ui_class: str | None = None
156+
widget: UIWidget
157+
ui_class: UIClass
156158
states: States
157159
type: ProductType
158160
place_oid: str
@@ -168,8 +170,8 @@ def __init__(
168170
controllable_name: str,
169171
definition: dict[str, Any],
170172
data_properties: list[dict[str, Any]] | None = None,
171-
widget: str | None = None,
172-
ui_class: str | None = None,
173+
widget: str,
174+
ui_class: str,
173175
states: list[dict[str, Any]] | None = None,
174176
type: int,
175177
place_oid: str,
@@ -185,8 +187,8 @@ def __init__(
185187
self.controllable_name = controllable_name
186188
self.states = States(states)
187189
self.data_properties = data_properties
188-
self.widget = widget
189-
self.ui_class = ui_class
190+
self.widget = UIWidget(widget)
191+
self.ui_class = UIClass(ui_class)
190192
self.type = ProductType(type)
191193
self.place_oid = place_oid
192194

0 commit comments

Comments
 (0)