From e131f58849f66bc23201ce56fc06da1329970f6c Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 16 Jan 2025 20:52:55 +0100 Subject: [PATCH] Reimplemented group entities --- src/core/__init__.py | 2 ++ src/core/entity.py | 12 ++++++++++-- src/core/group.py | 6 ++++++ src/core/room.py | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/core/group.py create mode 100644 src/core/room.py diff --git a/src/core/__init__.py b/src/core/__init__.py index 6c887bc..d2b9ea2 100644 --- a/src/core/__init__.py +++ b/src/core/__init__.py @@ -1,2 +1,4 @@ from .bridge import Bridge, BridgeException from .entity import Entity +from .group import Group +from .room import Room diff --git a/src/core/entity.py b/src/core/entity.py index 3c7442e..14264eb 100644 --- a/src/core/entity.py +++ b/src/core/entity.py @@ -1,6 +1,13 @@ class Entity: + def __init__( - self, *, id: str, name: str, room: str, device_type: str, groups: list[str] = [] + self, + *, + id: str, + name: str, + room: str | None, + device_type: str, + groups: list[str] = [], ) -> None: self._id = id self._name = name @@ -18,7 +25,8 @@ class Entity: return self._name @property - def room(self) -> str: + def room(self) -> str | None: + """Returns the room of the entity. Meta entities, like groups and rooms, are usually not part of rooms and likely return None.""" return self._room @property diff --git a/src/core/group.py b/src/core/group.py new file mode 100644 index 0000000..2b0098a --- /dev/null +++ b/src/core/group.py @@ -0,0 +1,6 @@ +from core import Entity + + +class Group(Entity): + def __init__(self, *, id: str, name: str): + super().__init__(id=id, name=name, room=None, device_type="group") diff --git a/src/core/room.py b/src/core/room.py new file mode 100644 index 0000000..4e5c6cb --- /dev/null +++ b/src/core/room.py @@ -0,0 +1,7 @@ +from core import Group + + +class Room(Group): + def __init__(self, *, id: str, name: str): + super().__init__(id=id, name=name) + self._device_type = "room"