1 """Support for Daikin AC sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from pydaikin.daikin_base
import Appliance
13 SensorEntityDescription,
27 from .
import DOMAIN
as DAIKIN_DOMAIN
29 ATTR_COMPRESSOR_FREQUENCY,
34 ATTR_INSIDE_TEMPERATURE,
35 ATTR_OUTSIDE_TEMPERATURE,
37 ATTR_TOTAL_ENERGY_TODAY,
40 from .coordinator
import DaikinCoordinator
41 from .entity
import DaikinEntity
44 @dataclass(frozen=True, kw_only=True)
46 """Describes Daikin sensor entity."""
48 value_func: Callable[[Appliance], float |
None]
51 SENSOR_TYPES: tuple[DaikinSensorEntityDescription, ...] = (
53 key=ATTR_INSIDE_TEMPERATURE,
54 translation_key=
"inside_temperature",
55 device_class=SensorDeviceClass.TEMPERATURE,
56 state_class=SensorStateClass.MEASUREMENT,
57 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
58 value_func=
lambda device: device.inside_temperature,
61 key=ATTR_OUTSIDE_TEMPERATURE,
62 translation_key=
"outside_temperature",
63 device_class=SensorDeviceClass.TEMPERATURE,
64 state_class=SensorStateClass.MEASUREMENT,
65 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
66 value_func=
lambda device: device.outside_temperature,
70 device_class=SensorDeviceClass.HUMIDITY,
71 state_class=SensorStateClass.MEASUREMENT,
72 native_unit_of_measurement=PERCENTAGE,
73 value_func=
lambda device: device.humidity,
76 key=ATTR_TARGET_HUMIDITY,
77 translation_key=
"target_humidity",
78 device_class=SensorDeviceClass.HUMIDITY,
79 state_class=SensorStateClass.MEASUREMENT,
80 native_unit_of_measurement=PERCENTAGE,
81 value_func=
lambda device: device.humidity,
85 translation_key=
"compressor_estimated_power_consumption",
86 device_class=SensorDeviceClass.POWER,
87 state_class=SensorStateClass.MEASUREMENT,
88 native_unit_of_measurement=UnitOfPower.KILO_WATT,
89 value_func=
lambda device: round(device.current_total_power_consumption, 2),
93 translation_key=
"cool_energy_consumption",
94 device_class=SensorDeviceClass.ENERGY,
95 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
96 entity_registry_enabled_default=
False,
97 value_func=
lambda device: round(device.last_hour_cool_energy_consumption, 2),
100 key=ATTR_HEAT_ENERGY,
101 translation_key=
"heat_energy_consumption",
102 device_class=SensorDeviceClass.ENERGY,
103 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
104 entity_registry_enabled_default=
False,
105 value_func=
lambda device: round(device.last_hour_heat_energy_consumption, 2),
108 key=ATTR_ENERGY_TODAY,
109 translation_key=
"energy_consumption",
110 device_class=SensorDeviceClass.ENERGY,
111 state_class=SensorStateClass.TOTAL_INCREASING,
112 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
113 value_func=
lambda device: round(device.today_energy_consumption, 2),
116 key=ATTR_COMPRESSOR_FREQUENCY,
117 translation_key=
"compressor_frequency",
118 device_class=SensorDeviceClass.FREQUENCY,
119 state_class=SensorStateClass.MEASUREMENT,
120 native_unit_of_measurement=UnitOfFrequency.HERTZ,
121 entity_registry_enabled_default=
False,
122 value_func=
lambda device: device.compressor_frequency,
125 key=ATTR_TOTAL_ENERGY_TODAY,
126 translation_key=
"compressor_energy_consumption",
127 device_class=SensorDeviceClass.ENERGY,
128 state_class=SensorStateClass.TOTAL_INCREASING,
129 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
130 entity_registry_enabled_default=
False,
131 value_func=
lambda device: round(device.today_total_energy_consumption, 2),
137 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
139 """Set up Daikin climate based on config_entry."""
140 daikin_api = hass.data[DAIKIN_DOMAIN].
get(entry.entry_id)
141 sensors = [ATTR_INSIDE_TEMPERATURE]
142 if daikin_api.device.support_outside_temperature:
143 sensors.append(ATTR_OUTSIDE_TEMPERATURE)
144 if daikin_api.device.support_energy_consumption:
145 sensors.append(ATTR_ENERGY_TODAY)
146 sensors.append(ATTR_COOL_ENERGY)
147 sensors.append(ATTR_HEAT_ENERGY)
148 sensors.append(ATTR_TOTAL_POWER)
149 sensors.append(ATTR_TOTAL_ENERGY_TODAY)
150 if daikin_api.device.support_humidity:
151 sensors.append(ATTR_HUMIDITY)
152 sensors.append(ATTR_TARGET_HUMIDITY)
153 if daikin_api.device.support_compressor_frequency:
154 sensors.append(ATTR_COMPRESSOR_FREQUENCY)
158 for description
in SENSOR_TYPES
159 if description.key
in sensors
165 """Representation of a Sensor."""
167 entity_description: DaikinSensorEntityDescription
170 self, coordinator: DaikinCoordinator, description: DaikinSensorEntityDescription
172 """Initialize the sensor."""
179 """Return the state of the sensor."""
float|None native_value(self)
None __init__(self, DaikinCoordinator coordinator, DaikinSensorEntityDescription description)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)