Skip to content

Commit d8cffb5

Browse files
committed
Add default values for ui_class and widget in Device model and validate their presence
1 parent 94fb9d3 commit d8cffb5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pyoverkiz/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ class Device:
388388
definition: Definition | None = None
389389
states: States = field(factory=States)
390390
type: ProductType
391-
ui_class: UIClass | None = None
392-
widget: UIWidget | None = None
391+
ui_class: UIClass = field(default=None) # type: ignore[assignment]
392+
widget: UIWidget = field(default=None) # type: ignore[assignment]
393393
identifier: DeviceIdentifier = field(init=False, repr=False)
394394
oid: str | None = field(repr=obfuscate_id, default=None)
395395
place_oid: str | None = None
@@ -411,6 +411,9 @@ def __attrs_post_init__(self) -> None:
411411
if self.widget is None and self.definition.widget_name:
412412
self.widget = UIWidget(self.definition.widget_name)
413413

414+
if self.ui_class is None or self.widget is None:
415+
raise ValueError(f"Device {self.device_url} is missing ui_class or widget")
416+
414417
def supports_command(self, command: str | OverkizCommand) -> bool:
415418
"""Check if device supports a command."""
416419
return self.definition is not None and str(command) in self.definition.commands

0 commit comments

Comments
 (0)