From f923cc647679f5eff3a8363cf7724f57b52c4f39 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Thu, 3 Nov 2022 06:51:47 +0000 Subject: [PATCH 1/3] Fix misc device types and add stubs for unknown --- src/pyatmo/modules/__init__.py | 2 ++ src/pyatmo/modules/device_types.py | 2 ++ src/pyatmo/modules/legrand.py | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pyatmo/modules/__init__.py b/src/pyatmo/modules/__init__.py index f647bb79..adbb31d3 100644 --- a/src/pyatmo/modules/__init__.py +++ b/src/pyatmo/modules/__init__.py @@ -25,6 +25,7 @@ NLT, NLUI, NLV, + NLunknown, ) from .module import Camera, Dimmer, Module, Shutter, Switch from .netatmo import ( @@ -102,6 +103,7 @@ "NOC", "NRV", "NSD", + "NLunknown", "OTH", "OTM", "Place", diff --git a/src/pyatmo/modules/device_types.py b/src/pyatmo/modules/device_types.py index 11a28556..466e4aea 100644 --- a/src/pyatmo/modules/device_types.py +++ b/src/pyatmo/modules/device_types.py @@ -47,6 +47,7 @@ class DeviceType(str, Enum): # Legrand Wiring devices and electrical panel products NLC = "NLC" # Cable outlet + NLD = "NLD" # Dimmer NLE = "NLE" # Connected Ecometer NLF = "NLF" # 2 wire light switch NLFN = "NLFN" # light switch with neutral @@ -67,6 +68,7 @@ class DeviceType(str, Enum): NLT = "NLT" # Global remote control NLV = "NLV" # Legrand / BTicino shutters NLUI = "NLUI" # Legrand device stub + NLunknown = "NLunknown" # Legrand device stub # BTicino Classe 300 EOS BNCX = "BNCX" # internal panel = gateway diff --git a/src/pyatmo/modules/legrand.py b/src/pyatmo/modules/legrand.py index 71e97e3e..1990719a 100644 --- a/src/pyatmo/modules/legrand.py +++ b/src/pyatmo/modules/legrand.py @@ -107,4 +107,8 @@ class NLC(FirmwareMixin, SwitchMixin, Module): class NLUI(FirmwareMixin, Module): - """Legrand NLUI device stubs.""" + """Legrand NLUI device stub.""" + + +class NLunknown(Module): + """NLunknown device stub.""" From 1444d6b5ad714857e0d43247db731407ac1a8853 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Thu, 3 Nov 2022 06:55:42 +0000 Subject: [PATCH 2/3] Add NLUF device stub --- src/pyatmo/modules/__init__.py | 12 +++++++----- src/pyatmo/modules/device_types.py | 1 + src/pyatmo/modules/legrand.py | 4 ++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pyatmo/modules/__init__.py b/src/pyatmo/modules/__init__.py index adbb31d3..7ec6d01e 100644 --- a/src/pyatmo/modules/__init__.py +++ b/src/pyatmo/modules/__init__.py @@ -23,6 +23,7 @@ NLPS, NLPT, NLT, + NLUF, NLUI, NLV, NLunknown, @@ -53,9 +54,9 @@ from .smarther import BNS __all__ = [ - "BNS", "BNCX", "BNDL", + "BNS", "BNSL", "Camera", "Dimmer", @@ -71,8 +72,8 @@ "NAPlug", "NATherm1", "NBG", - "NBR", "NBO", + "NBR", "NBS", "NCO", "NDB", @@ -82,8 +83,8 @@ "NLD", "NLE", "NLF", - "NLFN", "NLFE", + "NLFN", "NLG", "NLIS", "NLL", @@ -98,12 +99,13 @@ "NLPS", "NLPT", "NLT", - "NLV", + "NLUF", "NLUI", + "NLunknown", + "NLV", "NOC", "NRV", "NSD", - "NLunknown", "OTH", "OTM", "Place", diff --git a/src/pyatmo/modules/device_types.py b/src/pyatmo/modules/device_types.py index 466e4aea..7a201eec 100644 --- a/src/pyatmo/modules/device_types.py +++ b/src/pyatmo/modules/device_types.py @@ -69,6 +69,7 @@ class DeviceType(str, Enum): NLV = "NLV" # Legrand / BTicino shutters NLUI = "NLUI" # Legrand device stub NLunknown = "NLunknown" # Legrand device stub + NLUF = "NLUF" # Legrand device stub # BTicino Classe 300 EOS BNCX = "BNCX" # internal panel = gateway diff --git a/src/pyatmo/modules/legrand.py b/src/pyatmo/modules/legrand.py index 1990719a..401ad1b9 100644 --- a/src/pyatmo/modules/legrand.py +++ b/src/pyatmo/modules/legrand.py @@ -110,5 +110,9 @@ class NLUI(FirmwareMixin, Module): """Legrand NLUI device stub.""" +class NLUF(FirmwareMixin, Module): + """Legrand NLUF device stub.""" + + class NLunknown(Module): """NLunknown device stub.""" From 3cdcbe9c6fc27f827b4ba16bf69ae15470d64f96 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Thu, 3 Nov 2022 08:35:04 +0000 Subject: [PATCH 3/3] Handle unknown device types and log --- src/pyatmo/home.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pyatmo/home.py b/src/pyatmo/home.py index 694d4655..7e561315 100644 --- a/src/pyatmo/home.py +++ b/src/pyatmo/home.py @@ -19,6 +19,7 @@ ) from pyatmo.event import Event from pyatmo.exceptions import InvalidState, NoSchedule +from pyatmo.modules import Module from pyatmo.person import Person from pyatmo.room import Room from pyatmo.schedule import Schedule @@ -36,7 +37,7 @@ class Home: entity_id: str name: str rooms: dict[str, Room] - modules: dict[str, modules.Module] + modules: dict[str, Module] schedules: dict[str, Schedule] persons: dict[str, Person] events: dict[str, Event] @@ -46,10 +47,7 @@ def __init__(self, auth: AbstractAsyncAuth, raw_data: RawData) -> None: self.entity_id = raw_data["id"] self.name = raw_data.get("name", "Unknown") self.modules = { - module["id"]: getattr(modules, module["type"])( - home=self, - module=module, - ) + module["id"]: self.get_module(module) for module in raw_data.get("modules", []) } self.rooms = { @@ -69,6 +67,19 @@ def __init__(self, auth: AbstractAsyncAuth, raw_data: RawData) -> None: } self.events = {} + def get_module(self, module) -> Module: + try: + return getattr(modules, module["type"])( + home=self, + module=module, + ) + except AttributeError: + LOG.info("Unknown device type %s", module["type"]) + return getattr(modules, "NLunknown")( + home=self, + module=module, + ) + def update_topology(self, raw_data: RawData) -> None: self.name = raw_data.get("name", "Unknown")