Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions homeassistant/components/vesync/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Common utilities for VeSync Component."""

import logging
from typing import TypeGuard

from pyvesync.base_devices import VeSyncHumidifier
from pyvesync.base_devices.fan_base import VeSyncFanBase
from pyvesync.base_devices.fryer_base import VeSyncFryer
from pyvesync.base_devices.outlet_base import VeSyncOutlet
from pyvesync.base_devices.purifier_base import VeSyncPurifier
from pyvesync.base_devices.vesyncbasedevice import VeSyncBaseDevice
from pyvesync.const import ProductTypes
from pyvesync.devices.vesyncswitch import VeSyncWallSwitch

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -35,37 +37,39 @@ def rgetattr(obj: object, attr: str) -> object | str | None:
return obj


def is_humidifier(device: VeSyncBaseDevice) -> bool:
def is_humidifier(device: VeSyncBaseDevice) -> TypeGuard[VeSyncHumidifier]:
"""Check if the device represents a humidifier."""

return isinstance(device, VeSyncHumidifier)
return device.product_type == ProductTypes.HUMIDIFIER


def is_fan(device: VeSyncBaseDevice) -> bool:
def is_fan(device: VeSyncBaseDevice) -> TypeGuard[VeSyncFanBase]:
"""Check if the device represents a fan."""

return isinstance(device, VeSyncFanBase)
return device.product_type == ProductTypes.FAN


def is_outlet(device: VeSyncBaseDevice) -> bool:
def is_outlet(device: VeSyncBaseDevice) -> TypeGuard[VeSyncOutlet]:
"""Check if the device represents an outlet."""

return isinstance(device, VeSyncOutlet)
return device.product_type == ProductTypes.OUTLET


def is_wall_switch(device: VeSyncBaseDevice) -> bool:
def is_wall_switch(device: VeSyncBaseDevice) -> TypeGuard[VeSyncWallSwitch]:
"""Check if the device represents a wall switch, note this doessn't include dimming switches."""
if device.product_type != ProductTypes.SWITCH:
return False

return isinstance(device, VeSyncWallSwitch)
return getattr(device, "supports_dimmable", False) is False


def is_purifier(device: VeSyncBaseDevice) -> bool:
def is_purifier(device: VeSyncBaseDevice) -> TypeGuard[VeSyncPurifier]:
"""Check if the device represents an air purifier."""

return isinstance(device, VeSyncPurifier)
return device.product_type == ProductTypes.PURIFIER


def is_air_fryer(device: VeSyncBaseDevice) -> bool:
def is_air_fryer(device: VeSyncBaseDevice) -> TypeGuard[VeSyncFryer]:
"""Check if the device represents an air fryer."""

return isinstance(device, VeSyncFryer)
return device.product_type == ProductTypes.AIR_FRYER