Skip to content

Commit

Permalink
Update device model (#302)
Browse files Browse the repository at this point in the history
* Update model

* Update model

* Catch unknown enums
  • Loading branch information
iMicknl committed Jan 6, 2022
1 parent 326945a commit 9b7bca0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 17 additions & 0 deletions pyoverkiz/enums/ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging
from enum import Enum, unique

_LOGGER = logging.getLogger(__name__)


@unique
class UIClass(str, Enum):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
14 changes: 8 additions & 6 deletions pyoverkiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
GatewaySubType,
GatewayType,
ProductType,
UIClass,
UIWidget,
UpdateBoxStatus,
)

Expand Down Expand Up @@ -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
Expand All @@ -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: str,
ui_class: str,
states: list[dict[str, Any]] | None = None,
type: int,
place_oid: str,
Expand All @@ -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

Expand Down

0 comments on commit 9b7bca0

Please sign in to comment.