1 """Support for power sensors in WeMo Insight devices."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import cast
12 SensorEntityDescription,
21 from .
import async_wemo_dispatcher_connect
22 from .coordinator
import DeviceCoordinator
23 from .entity
import WemoEntity
26 @dataclass(frozen=True)
28 """SensorEntityDescription for WeMo AttributeSensor entities."""
32 name: str |
None =
None
33 state_conversion: Callable[[StateType], StateType] |
None =
None
34 unique_id_suffix: str |
None =
None
40 device_class=SensorDeviceClass.POWER,
41 state_class=SensorStateClass.MEASUREMENT,
42 native_unit_of_measurement=UnitOfPower.WATT,
43 key=
"current_power_watts",
44 unique_id_suffix=
"currentpower",
45 state_conversion=
lambda state: round(cast(float, state), 2),
49 device_class=SensorDeviceClass.ENERGY,
50 state_class=SensorStateClass.TOTAL_INCREASING,
51 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
53 unique_id_suffix=
"todaymw",
54 state_conversion=
lambda state: round(cast(float, state), 2),
61 _config_entry: ConfigEntry,
62 async_add_entities: AddEntitiesCallback,
64 """Set up WeMo sensors."""
66 async
def _discovered_wemo(coordinator: DeviceCoordinator) ->
None:
67 """Handle a discovered Wemo device."""
70 for description
in ATTRIBUTE_SENSORS
71 if hasattr(coordinator.wemo, description.key)
78 """Sensor that reads attributes of a wemo device."""
80 entity_description: AttributeSensorDescription
83 self, coordinator: DeviceCoordinator, description: AttributeSensorDescription
85 """Init AttributeSensor."""
91 """Return the name of the entity."""
96 """Suffix to append to the WeMo device's unique ID."""
100 """Convert native state to a value appropriate for the sensor."""
103 return convert(value)
107 """Return the value of the device attribute."""
StateType convert_state(self, StateType value)
None __init__(self, DeviceCoordinator coordinator, AttributeSensorDescription description)
str|None unique_id_suffix(self)
StateType native_value(self)
str|None name_suffix(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry _config_entry, AddEntitiesCallback async_add_entities)
None async_wemo_dispatcher_connect(HomeAssistant hass, DispatchCallback dispatch)