1 """Switcher integration Sensor platform."""
3 from __future__
import annotations
5 from aioswitcher.device
import DeviceCategory
10 SensorEntityDescription,
20 from .const
import SIGNAL_DEVICE_ADD
21 from .coordinator
import SwitcherDataUpdateCoordinator
22 from .entity
import SwitcherEntity
24 POWER_SENSORS: list[SensorEntityDescription] = [
26 key=
"power_consumption",
27 native_unit_of_measurement=UnitOfPower.WATT,
28 device_class=SensorDeviceClass.POWER,
29 state_class=SensorStateClass.MEASUREMENT,
32 key=
"electric_current",
33 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
34 device_class=SensorDeviceClass.CURRENT,
35 state_class=SensorStateClass.MEASUREMENT,
38 TIME_SENSORS: list[SensorEntityDescription] = [
41 translation_key=
"remaining_time",
45 translation_key=
"auto_shutdown",
46 entity_registry_enabled_default=
False,
49 TEMPERATURE_SENSORS: list[SensorEntityDescription] = [
52 translation_key=
"temperature",
56 POWER_PLUG_SENSORS = POWER_SENSORS
57 WATER_HEATER_SENSORS = [*POWER_SENSORS, *TIME_SENSORS]
58 THERMOSTAT_SENSORS = TEMPERATURE_SENSORS
63 config_entry: ConfigEntry,
64 async_add_entities: AddEntitiesCallback,
66 """Set up Switcher sensor from config entry."""
69 def async_add_sensors(coordinator: SwitcherDataUpdateCoordinator) ->
None:
70 """Add sensors from Switcher device."""
71 if coordinator.data.device_type.category == DeviceCategory.POWER_PLUG:
74 for description
in POWER_PLUG_SENSORS
76 elif coordinator.data.device_type.category == DeviceCategory.WATER_HEATER:
79 for description
in WATER_HEATER_SENSORS
81 elif coordinator.data.device_type.category == DeviceCategory.THERMOSTAT:
84 for description
in THERMOSTAT_SENSORS
87 config_entry.async_on_unload(
93 """Representation of a Switcher sensor entity."""
97 coordinator: SwitcherDataUpdateCoordinator,
98 description: SensorEntityDescription,
100 """Initialize the entity."""
105 f
"{coordinator.device_id}-{coordinator.mac_address}-{description.key}"
110 """Return value of sensor."""
StateType native_value(self)
None __init__(self, SwitcherDataUpdateCoordinator coordinator, SensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)