13
13
from homeassistant .const import UnitOfEnergy
14
14
from homeassistant .core import callback
15
15
from homeassistant .helpers .update_coordinator import CoordinatorEntity
16
+ from homeassistant .core import HomeAssistant
17
+ from homeassistant .helpers .entity import EntityCategory
16
18
17
19
from .const import COORDINATOR
20
+ from .const import DAIKIN_API
18
21
from .const import DAIKIN_DEVICES
19
22
from .const import DOMAIN as DAIKIN_DOMAIN
20
23
from .const import ENABLED_DEFAULT
@@ -38,6 +41,7 @@ async def async_setup(hass, async_add_entities):
38
41
async def async_setup_entry (hass , config_entry , async_add_entities ):
39
42
"""Set up Daikin climate based on config_entry."""
40
43
coordinator = hass .data [DAIKIN_DOMAIN ][COORDINATOR ]
44
+ daikin_api = hass .data [DAIKIN_DOMAIN ][DAIKIN_API ]
41
45
sensors = []
42
46
supported_management_point_types = {
43
47
"domesticHotWaterTank" ,
@@ -46,6 +50,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
46
50
"climateControlMainZone" ,
47
51
}
48
52
for dev_id , device in hass .data [DAIKIN_DOMAIN ][DAIKIN_DEVICES ].items ():
53
+ # For each rate limit we provide a sensor
54
+ for name in daikin_api .rate_limits .keys ():
55
+ sensors .append (DaikinLimitSensor (hass , device , coordinator , name ))
56
+
49
57
management_points = device .daikin_data .get ("managementPoints" , [])
50
58
for management_point in management_points :
51
59
management_point_type = management_point ["managementPointType" ]
@@ -65,15 +73,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
65
73
# operationMode is handled by the HWT and ClimateControl directly, so don't create a separate sensor for that
66
74
pass
67
75
elif value_value is not None and not isinstance (value_value , dict ):
68
- sensor2 = DaikinValueSensor (
69
- device ,
70
- coordinator ,
71
- embedded_id ,
72
- management_point_type ,
73
- None ,
74
- value ,
76
+ sensors .append (
77
+ DaikinValueSensor (
78
+ device ,
79
+ coordinator ,
80
+ embedded_id ,
81
+ management_point_type ,
82
+ None ,
83
+ value ,
84
+ )
75
85
)
76
- sensors .append (sensor2 )
77
86
78
87
sd = management_point .get ("sensoryData" )
79
88
if sd is not None :
@@ -82,15 +91,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
82
91
if sensory_data is not None :
83
92
for sensor in sensory_data :
84
93
_LOGGER .info ("Device '%s' provides sensor '%s'" , device .name , sensor )
85
- sensor2 = DaikinValueSensor (
86
- device ,
87
- coordinator ,
88
- embedded_id ,
89
- management_point_type ,
90
- "sensoryData" ,
91
- sensor ,
94
+ sensors .append (
95
+ DaikinValueSensor (
96
+ device ,
97
+ coordinator ,
98
+ embedded_id ,
99
+ management_point_type ,
100
+ "sensoryData" ,
101
+ sensor ,
102
+ )
92
103
)
93
- sensors .append (sensor2 )
94
104
95
105
cd = management_point .get ("consumptionData" )
96
106
if cd is not None :
@@ -126,16 +136,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
126
136
periodName = SENSOR_PERIODS [period ]
127
137
sensor = f"{ device .name } { management_point_type } { mode } { periodName } "
128
138
_LOGGER .info ("Proposing sensor '%s'" , sensor )
129
- sensorv = DaikinEnergySensor (
130
- device ,
131
- coordinator ,
132
- embedded_id ,
133
- management_point_type ,
134
- mode ,
135
- period ,
136
- icon ,
139
+ sensors .append (
140
+ DaikinEnergySensor (
141
+ device ,
142
+ coordinator ,
143
+ embedded_id ,
144
+ management_point_type ,
145
+ mode ,
146
+ period ,
147
+ icon ,
148
+ )
137
149
)
138
- sensors .append (sensorv )
139
150
else :
140
151
_LOGGER .info (
141
152
"Ignoring consumption data '%s', not a supported operation_mode" ,
@@ -303,3 +314,49 @@ def available(self):
303
314
def device_info (self ):
304
315
"""Return a device description for device registry."""
305
316
return self ._device .device_info ()
317
+
318
+
319
+ class DaikinLimitSensor (CoordinatorEntity , SensorEntity ):
320
+
321
+ def __init__ (
322
+ self ,
323
+ hass : HomeAssistant ,
324
+ device : Appliance ,
325
+ coordinator ,
326
+ limit_key ,
327
+ ) -> None :
328
+ _LOGGER .info ("Device '%s' LimitSensor '%s'" , device .name , limit_key )
329
+ super ().__init__ (coordinator )
330
+ self ._hass = hass
331
+ self ._device = device
332
+ self ._limit_key = limit_key
333
+ self ._attr_has_entity_name = True
334
+ self ._attr_icon = "mdi:information-outline"
335
+ self ._attr_entity_category = EntityCategory .DIAGNOSTIC
336
+ self ._attr_name = f"RateLimit { self ._limit_key } "
337
+ self ._attr_unique_id = f"{ self ._device .getId ()} _limitsensor_{ self ._limit_key } "
338
+ self ._attr_native_value = self .sensor_value ()
339
+ _LOGGER .info (
340
+ "Device '%s:%s' supports sensor '%s'" ,
341
+ device .name ,
342
+ self ._attr_name ,
343
+ )
344
+
345
+ @callback
346
+ def _handle_coordinator_update (self ) -> None :
347
+ self ._attr_native_value = self .sensor_value ()
348
+ self .async_write_ha_state ()
349
+
350
+ def sensor_value (self ):
351
+ daikin_api = self ._hass .data [DAIKIN_DOMAIN ][DAIKIN_API ]
352
+ return daikin_api .rate_limits [self ._limit_key ]
353
+
354
+ @property
355
+ def available (self ):
356
+ """Return the availability of the underlying device."""
357
+ return self ._device .available
358
+
359
+ @property
360
+ def device_info (self ):
361
+ """Return a device description for device registry."""
362
+ return self ._device .device_info ()
0 commit comments