Skip to content

Commit

Permalink
Merge pull request #355 from cgtobi/add_EBU
Browse files Browse the repository at this point in the history
Add missing devices and implement more graceful handling of unknown device types
  • Loading branch information
jabesq authored Nov 5, 2022
2 parents 0e13666 + 3cdcbe9 commit a6d024b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/pyatmo/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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 = {
Expand All @@ -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")

Expand Down
12 changes: 8 additions & 4 deletions src/pyatmo/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
NLPS,
NLPT,
NLT,
NLUF,
NLUI,
NLV,
NLunknown,
)
from .module import Camera, Dimmer, Module, Shutter, Switch
from .netatmo import (
Expand Down Expand Up @@ -52,9 +54,9 @@
from .smarther import BNS

__all__ = [
"BNS",
"BNCX",
"BNDL",
"BNS",
"BNSL",
"Camera",
"Dimmer",
Expand All @@ -70,8 +72,8 @@
"NAPlug",
"NATherm1",
"NBG",
"NBR",
"NBO",
"NBR",
"NBS",
"NCO",
"NDB",
Expand All @@ -81,8 +83,8 @@
"NLD",
"NLE",
"NLF",
"NLFN",
"NLFE",
"NLFN",
"NLG",
"NLIS",
"NLL",
Expand All @@ -97,8 +99,10 @@
"NLPS",
"NLPT",
"NLT",
"NLV",
"NLUF",
"NLUI",
"NLunknown",
"NLV",
"NOC",
"NRV",
"NSD",
Expand Down
3 changes: 3 additions & 0 deletions src/pyatmo/modules/device_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,6 +68,8 @@ class DeviceType(str, Enum):
NLT = "NLT" # Global remote control
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
Expand Down
10 changes: 9 additions & 1 deletion src/pyatmo/modules/legrand.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ class NLC(FirmwareMixin, SwitchMixin, Module):


class NLUI(FirmwareMixin, Module):
"""Legrand NLUI device stubs."""
"""Legrand NLUI device stub."""


class NLUF(FirmwareMixin, Module):
"""Legrand NLUF device stub."""


class NLunknown(Module):
"""NLunknown device stub."""

0 comments on commit a6d024b

Please sign in to comment.