From cb08bc44492fd8d12ba6190f45accbe34d9cd6e2 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Thu, 6 Jan 2022 13:30:52 +0000 Subject: [PATCH 1/3] Update model --- pyoverkiz/models.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pyoverkiz/models.py b/pyoverkiz/models.py index e088e907..45b70665 100644 --- a/pyoverkiz/models.py +++ b/pyoverkiz/models.py @@ -16,6 +16,8 @@ GatewayType, ProductType, UpdateBoxStatus, + UIWidget, + UIClass, ) # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals @@ -151,8 +153,8 @@ class Device: controllable_name: str definition: Definition data_properties: list[dict[str, Any]] | None = None - widget: str | None = None - ui_class: str | None = None + widget: UIWidget + ui_class: UIClass states: States type: ProductType place_oid: str @@ -168,8 +170,8 @@ def __init__( controllable_name: str, definition: dict[str, Any], data_properties: list[dict[str, Any]] | None = None, - widget: str | None = None, - ui_class: str | None = None, + widget: UIWidget + ui_class: UIClass states: list[dict[str, Any]] | None = None, type: int, place_oid: str, @@ -185,8 +187,8 @@ def __init__( self.controllable_name = controllable_name self.states = States(states) self.data_properties = data_properties - self.widget = widget - self.ui_class = ui_class + self.widget = UIWidget(widget) + self.ui_class = UIClass(ui_class) self.type = ProductType(type) self.place_oid = place_oid From fded170e596bb62047039919a3971aaba1b48381 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Thu, 6 Jan 2022 14:43:39 +0100 Subject: [PATCH 2/3] Update model --- pyoverkiz/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyoverkiz/models.py b/pyoverkiz/models.py index 45b70665..ada35474 100644 --- a/pyoverkiz/models.py +++ b/pyoverkiz/models.py @@ -15,9 +15,9 @@ GatewaySubType, GatewayType, ProductType, - UpdateBoxStatus, - UIWidget, UIClass, + UIWidget, + UpdateBoxStatus, ) # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals @@ -170,8 +170,8 @@ def __init__( controllable_name: str, definition: dict[str, Any], data_properties: list[dict[str, Any]] | None = None, - widget: UIWidget - ui_class: UIClass + widget: str, + ui_class: str, states: list[dict[str, Any]] | None = None, type: int, place_oid: str, From ad8a62a3580ad2d3ff63ddd3f7247d88d3008b82 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Thu, 6 Jan 2022 15:43:12 +0100 Subject: [PATCH 3/3] Catch unknown enums --- pyoverkiz/enums/ui.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pyoverkiz/enums/ui.py b/pyoverkiz/enums/ui.py index 933c067c..2aa3b057 100644 --- a/pyoverkiz/enums/ui.py +++ b/pyoverkiz/enums/ui.py @@ -1,5 +1,8 @@ +import logging from enum import Enum, unique +_LOGGER = logging.getLogger(__name__) + @unique class UIClass(str, Enum): @@ -70,6 +73,13 @@ class UIClass(str, Enum): WINDOW = "Window" WINDOW_HANDLE = "WindowHandle" + UNKNOWN = "unknown" + + @classmethod + def _missing_(cls, value): # type: ignore + _LOGGER.warning(f"Unsupported value {value} has been returned for {cls}") + return cls.UNKNOWN + @unique class UIWidget(str, Enum): @@ -394,3 +404,10 @@ class UIWidget(str, Enum): ZWAVE_TRANSCEIVER = "ZWaveTransceiver" ZIGBEE_NETWORK = "ZigbeeNetwork" ZIGBEE_STACK = "ZigbeeStack" + + UNKNOWN = "unknown" + + @classmethod + def _missing_(cls, value): # type: ignore + _LOGGER.warning(f"Unsupported value {value} has been returned for {cls}") + return cls.UNKNOWN