Slimming stuff down
This commit is contained in:
parent
1d46b570f6
commit
7164d6e2fd
3 changed files with 58 additions and 63 deletions
|
@ -8,22 +8,22 @@ class EntityOpNotSupportedError(Exception):
|
|||
|
||||
class Entity:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
id: str,
|
||||
name: str,
|
||||
room: str | None,
|
||||
device_type: str,
|
||||
groups: list[str] = [],
|
||||
update_period: float = 1,
|
||||
) -> None:
|
||||
def __init__(self, *, id: str, name: str, category: str) -> None:
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._room = room
|
||||
self._device_type = device_type.strip().lower()
|
||||
self._groups = set(groups)
|
||||
self._update_period: float = update_period
|
||||
self._category = category.strip().lower()
|
||||
|
||||
self._on: bool = False
|
||||
self._color: Color = Color()
|
||||
self._message_queue: list[str] = []
|
||||
self._pattern
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} [{self.id}, {self.category}]"
|
||||
|
||||
async def update(self):
|
||||
"""Implements an entity specific update operation to get the latest state."""
|
||||
raise EntityOpNotSupportedError("update")
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
|
@ -34,17 +34,8 @@ class Entity:
|
|||
return self._name
|
||||
|
||||
@property
|
||||
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
|
||||
def device_type(self) -> str:
|
||||
return self._device_type
|
||||
|
||||
@property
|
||||
def groups(self) -> set[str]:
|
||||
return self._groups
|
||||
def category(self) -> str:
|
||||
return self._category
|
||||
|
||||
@property
|
||||
def update_period(self) -> float:
|
||||
|
@ -73,34 +64,3 @@ class Entity:
|
|||
@property
|
||||
def transition_time(self) -> float:
|
||||
raise EntityOpNotSupportedError("transition_time")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} [{self.id}, type {self.device_type}, room {self.room}, in {len(self.groups)} groups]"
|
||||
|
||||
async def update(self):
|
||||
"""Implements an entity specific update operation to get the latest state."""
|
||||
raise EntityOpNotSupportedError("update")
|
||||
|
||||
async def turn_on(self):
|
||||
"""Turns entity on, if action supported."""
|
||||
raise EntityOpNotSupportedError("turn_on")
|
||||
|
||||
async def turn_off(self):
|
||||
"""Turns entity on, if action supported."""
|
||||
raise EntityOpNotSupportedError("turn_off")
|
||||
|
||||
async def set_brightness(self, brightness: float):
|
||||
"""Does not turn an entity on if brightness > 0 and entity turned off."""
|
||||
raise EntityOpNotSupportedError("set_brightness")
|
||||
|
||||
async def set_hue(self, hue: float):
|
||||
raise EntityOpNotSupportedError("set_hue")
|
||||
|
||||
async def set_saturation(self, saturation: float):
|
||||
raise EntityOpNotSupportedError("set_saturation")
|
||||
|
||||
async def set_color(self, color: Color):
|
||||
raise EntityOpNotSupportedError("set_color")
|
||||
|
||||
async def set_transition_duration(self, seconds: float):
|
||||
raise EntityOpNotSupportedError("set_transition_duration")
|
||||
|
|
42
src/core/pattern.py
Normal file
42
src/core/pattern.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
class Pattern:
|
||||
def __init__(
|
||||
self, *, sequence: str = "01", active_ms: int = 1000, inactive_ms: int = 1000
|
||||
):
|
||||
self._sequence = None
|
||||
self._active_ms = None
|
||||
self._inactive_ms = None
|
||||
self.sequence = sequence # Use the setter for validation
|
||||
self.active_ms = active_ms # Use the setter for validation
|
||||
self.inactive_ms = inactive_ms # Use the setter for validation
|
||||
|
||||
@property
|
||||
def sequence(self) -> str:
|
||||
return self._sequence
|
||||
|
||||
@sequence.setter
|
||||
def sequence(self, value: str):
|
||||
if not isinstance(value, str):
|
||||
raise ValueError("Sequence must be a string.")
|
||||
if not all(char in "01" for char in value):
|
||||
raise ValueError("Sequence must only contain '0' and '1'.")
|
||||
self._sequence = value
|
||||
|
||||
@property
|
||||
def active_ms(self) -> int:
|
||||
return self._active_ms
|
||||
|
||||
@active_ms.setter
|
||||
def active_ms(self, value: int):
|
||||
if not isinstance(value, int) or value < 0:
|
||||
raise ValueError("Active milliseconds must be a non-negative integer.")
|
||||
self._active_ms = value
|
||||
|
||||
@property
|
||||
def inactive_ms(self) -> int:
|
||||
return self._inactive_ms
|
||||
|
||||
@inactive_ms.setter
|
||||
def inactive_ms(self, value: int):
|
||||
if not isinstance(value, int) or value < 0:
|
||||
raise ValueError("Inactive milliseconds must be a non-negative integer.")
|
||||
self._inactive_ms = value
|
|
@ -1,7 +0,0 @@
|
|||
from .group import Group
|
||||
|
||||
|
||||
class Room(Group):
|
||||
def __init__(self, *, id: str, name: str):
|
||||
super().__init__(id=id, name=name)
|
||||
self._device_type = "room"
|
Loading…
Reference in a new issue