Formatting

This commit is contained in:
Maximilian Giller 2022-11-04 09:03:53 +01:00
parent 069ee75bf3
commit f8cdd0f94d
4 changed files with 23 additions and 9 deletions

View file

@ -2,8 +2,10 @@ import abc
from models.light import LightColor
class GenericDevice:
"""A generic device."""
def __init__(self, name: str):
self.name = name
@ -41,4 +43,5 @@ class LightDevice(SwitchDevice):
class AllDevice(LightDevice):
"""Abstract device class that offers all device operations."""
pass

View file

@ -4,12 +4,23 @@ from models.exceptions import NoDeviceFoundError
from models.groups import DeviceGroup, Room
DEVICE_TYPE = TypeVar("DEVICE_TYPE", type(GenericDevice), type(SwitchDevice), type(LightDevice), type(Room), type(DeviceGroup))
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]:
"""Filters out devices that are not of a specific type."""
filtered_devices: list[type] = [device for device in devices if isinstance(device, type)]
filtered_devices: list[type] = [
device for device in devices if isinstance(device, type)
]
if len(filtered_devices) == 0:
raise NoDeviceFoundError(f"No devices of type {type} found.")