Fix VeSync device to match pyvesync type (#73034)
* vesync: change device to match pyvesync type * MartinHjelmare's suggestion for derived classes Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * MartinHjelmare's suggestion for derived classes Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * MartinHjelmare's suggestion for derived classes Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * MartinHjelmare's suggestion for annotations * vesync: fix imports Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
e74c711ef3
commit
0dc1e7d1e6
1 changed files with 16 additions and 6 deletions
|
@ -1,8 +1,14 @@
|
|||
"""Support for power & energy sensors for VeSync outlets."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from pyvesync.vesyncfan import VeSyncAirBypass
|
||||
from pyvesync.vesyncoutlet import VeSyncOutlet
|
||||
from pyvesync.vesyncswitch import VeSyncSwitch
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
|
@ -22,7 +28,7 @@ from homeassistant.helpers.entity import EntityCategory
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .common import VeSyncBaseEntity, VeSyncDevice
|
||||
from .common import VeSyncBaseEntity
|
||||
from .const import DEV_TYPE_TO_HA, DOMAIN, SKU_TO_BASE_DEVICE, VS_DISCOVERY, VS_SENSORS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -32,7 +38,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
class VeSyncSensorEntityDescriptionMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
value_fn: Callable[[VeSyncDevice], StateType]
|
||||
value_fn: Callable[[VeSyncAirBypass | VeSyncOutlet | VeSyncSwitch], StateType]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -41,8 +47,12 @@ class VeSyncSensorEntityDescription(
|
|||
):
|
||||
"""Describe VeSync sensor entity."""
|
||||
|
||||
exists_fn: Callable[[VeSyncDevice], bool] = lambda _: True
|
||||
update_fn: Callable[[VeSyncDevice], None] = lambda _: None
|
||||
exists_fn: Callable[
|
||||
[VeSyncAirBypass | VeSyncOutlet | VeSyncSwitch], bool
|
||||
] = lambda _: True
|
||||
update_fn: Callable[
|
||||
[VeSyncAirBypass | VeSyncOutlet | VeSyncSwitch], None
|
||||
] = lambda _: None
|
||||
|
||||
|
||||
def update_energy(device):
|
||||
|
@ -107,7 +117,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = (
|
|||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
value_fn=lambda device: device.details["energy"],
|
||||
value_fn=lambda device: device.energy_today,
|
||||
update_fn=update_energy,
|
||||
exists_fn=lambda device: ha_dev_type(device) == "outlet",
|
||||
),
|
||||
|
@ -151,7 +161,7 @@ class VeSyncSensorEntity(VeSyncBaseEntity, SensorEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
device: VeSyncDevice,
|
||||
device: VeSyncAirBypass | VeSyncOutlet | VeSyncSwitch,
|
||||
description: VeSyncSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the VeSync outlet device."""
|
||||
|
|
Loading…
Add table
Reference in a new issue