diff --git a/src/models/helper.py b/src/models/helper.py index 52fe107..8acc8dd 100644 --- a/src/models/helper.py +++ b/src/models/helper.py @@ -1,8 +1,9 @@ from typing import TypeVar 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]: diff --git a/src/models/home.py b/src/models/home.py new file mode 100644 index 0000000..9eb92a6 --- /dev/null +++ b/src/models/home.py @@ -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)