From 0b247755d329cf54d30b88a5175b2b7a79c30e20 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Wed, 2 Nov 2022 12:54:59 +0100 Subject: [PATCH] Basic concept of home --- src/models/helper.py | 3 ++- src/models/home.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/models/home.py 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)