Skip to content

Commit

Permalink
Merge pull request #95 from loopj/additional-station-types
Browse files Browse the repository at this point in the history
Add a bunch of missing station types
  • Loading branch information
loopj authored Apr 10, 2024
2 parents 810169f + 179a3d9 commit 537484d
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/aiovantage/command_client/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import logging
from collections import defaultdict
from collections.abc import Callable, Coroutine, Iterable, Sequence
from collections.abc import Awaitable, Callable, Iterable, Sequence
from contextlib import suppress
from enum import Enum
from inspect import iscoroutinefunction
Expand Down Expand Up @@ -71,7 +71,7 @@ class EnhancedLogEvent(TypedDict):
Event = ConnectEvent | DisconnectEvent | ReconnectEvent | StatusEvent | EnhancedLogEvent

# Type aliases for callbacks for event subscriptions
EventCallback = Callable[[Event], Coroutine | None]
EventCallback = Callable[[Event], Awaitable[None] | None]
EventFilter = Callable[[Event], bool]
EventSubscription = tuple[EventCallback, EventFilter | None]

Expand Down Expand Up @@ -181,7 +181,7 @@ def subscribe(
if isinstance(event_filter, EventType):
subscription = (callback, lambda event: event["type"] == event_filter)
elif isinstance(event_filter, Iterable):
subscription = (callback, lambda event: event["type"] in event_filter) # type: ignore[operator]
subscription = (callback, lambda event: event["type"] in event_filter)
else:
subscription = (callback, event_filter)

Expand Down
18 changes: 18 additions & 0 deletions src/aiovantage/config_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@
from .blind_group_base import BlindGroupBase
from .button import Button
from .child_device import ChildDevice
from .contact_input import ContactInput
from .custom_device import CustomDevice
from .dc_power_profile import DCPowerProfile
from .dimmer import Dimmer
from .din_contact_input import DINContactInput
from .din_high_voltage_relay_station import DINHighVoltageRelayStation
from .din_low_voltage_relay_station import DINLowVoltageRelayStation
from .din_station import DINStation
from .dry_contact import DryContact
from .dual_relay_station import DualRelayStation
from .eq_ctrl import EqCtrl
from .eq_ux import EqUX
from .gmem import GMem
from .high_voltage_relay_station import HighVoltageRelayStation
from .keypad import Keypad
from .light_sensor import LightSensor
from .load import Load
from .load_group import LoadGroup
from .location_object import LocationObject
from .low_voltage_relay_station import LowVoltageRelayStation
from .master import Master
from .module import Module
from .module_gen2 import ModuleGen2
Expand All @@ -33,6 +40,8 @@
from .qube_blind import QubeBlind
from .relay_blind import RelayBlind
from .rgb_load_base import RGBLoadBase
from .rs232_station import RS232Station
from .rs485_station import RS485Station
from .scene_point_relay import ScenePointRelay
from .sensor import Sensor
from .somfy_rs_485_group_child import SomfyRS485GroupChild
Expand Down Expand Up @@ -62,19 +71,26 @@
"BlindGroupBase",
"Button",
"ChildDevice",
"ContactInput",
"CustomDevice",
"DCPowerProfile",
"Dimmer",
"DINContactInput",
"DINHighVoltageRelayStation",
"DINLowVoltageRelayStation",
"DINStation",
"DryContact",
"DualRelayStation",
"EqCtrl",
"EqUX",
"GMem",
"HighVoltageRelayStation",
"Keypad",
"LightSensor",
"Load",
"LoadGroup",
"LocationObject",
"LowVoltageRelayStation",
"Master",
"Module",
"ModuleGen2",
Expand All @@ -88,6 +104,8 @@
"QubeBlind",
"RelayBlind",
"RGBLoadBase",
"RS232Station",
"RS485Station",
"ScenePointRelay",
"Sensor",
"SomfyRS485GroupChild",
Expand Down
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/contact_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Contact Input."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class ContactInput(StationObject):
"""Contact Input."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/din_contact_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""DIN Contact Input Station."""

from dataclasses import dataclass

from .din_station import DINStation


@dataclass
class DINContactInput(DINStation):
"""DIN Contact Input Station."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""DIN High Voltage Relay Station."""

from dataclasses import dataclass

from .din_station import DINStation


@dataclass
class DINHighVoltageRelayStation(DINStation):
"""DIN High Voltage Relay Station."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""DIN Low Voltage Relay Station."""

from dataclasses import dataclass

from .din_station import DINStation


@dataclass
class DINLowVoltageRelayStation(DINStation):
"""DIN Low Voltage Relay Station."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/din_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Base class for DIN station objects."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class DINStation(StationObject):
"""Base class for DIN station objects."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/high_voltage_relay_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""High Voltage Relay Station."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class HighVoltageRelayStation(StationObject):
"""High Voltage Relay Station."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/low_voltage_relay_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Low Voltage Relay Station."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class LowVoltageRelayStation(StationObject):
"""Low Voltage Relay Station."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/rs232_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""RS-232 Station."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class RS232Station(StationObject):
"""RS-232 Station."""
10 changes: 10 additions & 0 deletions src/aiovantage/config_client/models/rs485_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""RS-485 Station."""

from dataclasses import dataclass

from .station_object import StationObject


@dataclass
class RS485Station(StationObject):
"""RS-485 Station."""
8 changes: 8 additions & 0 deletions src/aiovantage/controllers/stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ class StationsController(BaseController[StationObject]):
"""

vantage_types = (
"ContactInput",
"Dimmer",
"DINContactInput",
"DINHighVoltageRelayStation",
"DINLowVoltageRelayStation",
"DualRelayStation",
"EqCtrl",
"EqUX",
"HighVoltageRelayStation",
"Keypad",
"LowVoltageRelayStation",
"RS232Station",
"RS485Station",
"ScenePointRelay",
"Vantage.DmxDaliGateway",
)
Expand Down
6 changes: 3 additions & 3 deletions src/aiovantage/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def filter(self, *args: Any, **kwargs: Any) -> "QuerySet[T]":
return queryset

@overload
def get(self, key: int, default: T | None = None) -> T | None: ...
def get(self, key: int) -> T | None: ...

@overload
def get(self, match: Callable[[T], Any]) -> T | None: ...
Expand All @@ -104,13 +104,13 @@ def get(self, *args: Any, **kwargs: Any) -> T | None:
"""Get the first object that matches the given filter."""
# Handle the case where we're getting an object by key
if len(args) == 1 and isinstance(args[0], int):
return self.__data.get(args[0], kwargs.get("default", None))
return self.__data.get(args[0], None)

# Otherwise, pass through to filter and return the first object
return next(iter(self.filter(*args, **kwargs)), None)

@overload
async def aget(self, key: int, default: T | None = None) -> T | None: ...
async def aget(self, key: int) -> T | None: ...

@overload
async def aget(self, match: Callable[[T], Any]) -> T | None: ...
Expand Down

0 comments on commit 537484d

Please sign in to comment.