11 lines
426 B
Python
11 lines
426 B
Python
|
from typing import TypeVar
|
||
|
from models.devices import GenericDevice, LightDevice, SwitchDevice
|
||
|
|
||
|
|
||
|
DEVICE_TYPE = TypeVar("DEVICE_TYPE", type(GenericDevice), type(SwitchDevice), type(LightDevice))
|
||
|
|
||
|
|
||
|
def filter_devices(devices: list[GenericDevice], type: DEVICE_TYPE) -> list[DEVICE_TYPE]:
|
||
|
"""Filters out devices that are not of a specific type."""
|
||
|
return [device for device in devices if isinstance(device, DEVICE_TYPE)]
|