mash-server/src/models/helper.py

12 lines
501 B
Python
Raw Normal View History

from typing import TypeVar
from models.devices import GenericDevice, LightDevice, SwitchDevice
2022-11-02 12:54:59 +01:00
from models.groups import DeviceGroup, Room
2022-11-02 12:54:59 +01:00
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]:
"""Filters out devices that are not of a specific type."""
return [device for device in devices if isinstance(device, DEVICE_TYPE)]