Formatting
This commit is contained in:
parent
069ee75bf3
commit
f8cdd0f94d
4 changed files with 23 additions and 9 deletions
|
@ -2,8 +2,10 @@ import abc
|
||||||
|
|
||||||
from models.light import LightColor
|
from models.light import LightColor
|
||||||
|
|
||||||
|
|
||||||
class GenericDevice:
|
class GenericDevice:
|
||||||
"""A generic device."""
|
"""A generic device."""
|
||||||
|
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
@ -41,4 +43,5 @@ class LightDevice(SwitchDevice):
|
||||||
|
|
||||||
class AllDevice(LightDevice):
|
class AllDevice(LightDevice):
|
||||||
"""Abstract device class that offers all device operations."""
|
"""Abstract device class that offers all device operations."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -4,12 +4,23 @@ from models.exceptions import NoDeviceFoundError
|
||||||
from models.groups import DeviceGroup, Room
|
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."""
|
"""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:
|
if len(filtered_devices) == 0:
|
||||||
raise NoDeviceFoundError(f"No devices of type {type} found.")
|
raise NoDeviceFoundError(f"No devices of type {type} found.")
|
||||||
|
|
Loading…
Reference in a new issue