Basic concept of home
This commit is contained in:
parent
457f4484f8
commit
0b247755d3
2 changed files with 21 additions and 1 deletions
|
@ -1,8 +1,9 @@
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from models.devices import GenericDevice, LightDevice, SwitchDevice
|
from models.devices import GenericDevice, LightDevice, SwitchDevice
|
||||||
|
from models.groups import DeviceGroup, Room
|
||||||
|
|
||||||
|
|
||||||
DEVICE_TYPE = TypeVar("DEVICE_TYPE", type(GenericDevice), type(SwitchDevice), type(LightDevice))
|
DEVICE_TYPE = TypeVar("DEVICE_TYPE", type(GenericDevice), type(SwitchDevice), type(LightDevice), type(Room), type(DeviceGroup))
|
||||||
|
|
||||||
|
|
||||||
def filter_devices(devices: list[GenericDevice], type: DEVICE_TYPE) -> list[DEVICE_TYPE]:
|
def filter_devices(devices: list[GenericDevice], type: DEVICE_TYPE) -> list[DEVICE_TYPE]:
|
||||||
|
|
19
src/models/home.py
Normal file
19
src/models/home.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from models.groups import DeviceGroup, Room
|
||||||
|
from models.helper import filter_devices
|
||||||
|
|
||||||
|
|
||||||
|
class Home(Room):
|
||||||
|
"""Combines all elements of a smart home."""
|
||||||
|
|
||||||
|
location: str
|
||||||
|
"""Physical location of the home, useful for sunset and sunrise times."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rooms(self) -> list[Room]:
|
||||||
|
"""Returns all rooms in the home."""
|
||||||
|
return filter_devices(self.devices, Room)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def groups(self) -> list[DeviceGroup]:
|
||||||
|
"""Returns all groups in the home."""
|
||||||
|
return filter_devices(self.devices, DeviceGroup)
|
Loading…
Reference in a new issue