@@ -37,6 +37,37 @@ async def async_setup(hass, async_add_entities):
37
37
"""
38
38
39
39
40
+ def handle_energy_sensors (coordinator , device , embedded_id , management_point_type , operation_modes , sensor_type , cdve , sensors ):
41
+ _LOGGER .info ("Device '%s' provides '%s'" , device .name , sensor_type )
42
+ for mode in cdve :
43
+ # Only handle consumptionData for an operation mode supported by this device
44
+ if mode in operation_modes :
45
+ _LOGGER .info (
46
+ "Device '%s' provides mode %s %s" ,
47
+ device .name ,
48
+ management_point_type ,
49
+ mode ,
50
+ )
51
+ for period in cdve [mode ]:
52
+ _LOGGER .info (
53
+ "Device '%s:%s' provides mode %s %s supports period %s" ,
54
+ device .name ,
55
+ embedded_id ,
56
+ management_point_type ,
57
+ mode ,
58
+ period ,
59
+ )
60
+ periodName = SENSOR_PERIODS [period ]
61
+ sensor = f"{ device .name } { sensor_type } { management_point_type } { mode } { periodName } "
62
+ _LOGGER .info ("Proposing sensor '%s'" , sensor )
63
+ sensors .append (DaikinEnergySensor (device , coordinator , embedded_id , management_point_type , sensor_type , mode , period ))
64
+ else :
65
+ _LOGGER .info (
66
+ "Ignoring consumption data '%s', not a supported operation_mode" ,
67
+ mode ,
68
+ )
69
+
70
+
40
71
async def async_setup_entry (hass , config_entry , async_add_entities ):
41
72
"""Set up Daikin climate based on config_entry."""
42
73
coordinator = hass .data [DAIKIN_DOMAIN ][COORDINATOR ]
@@ -115,34 +146,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
115
146
if cdv is not None :
116
147
cdve = cdv .get ("electrical" )
117
148
if cdve is not None :
118
- _LOGGER .info ("Device '%s' provides electrical" , device .name )
119
- for mode in cdve :
120
- # Only handle consumptionData for an operation mode supported by this device
121
- if mode in operation_modes :
122
- _LOGGER .info (
123
- "Device '%s' provides mode %s %s" ,
124
- device .name ,
125
- management_point_type ,
126
- mode ,
127
- )
128
- for period in cdve [mode ]:
129
- _LOGGER .info (
130
- "Device '%s:%s' provides mode %s %s supports period %s" ,
131
- device .name ,
132
- embedded_id ,
133
- management_point_type ,
134
- mode ,
135
- period ,
136
- )
137
- periodName = SENSOR_PERIODS [period ]
138
- sensor = f"{ device .name } { management_point_type } { mode } { periodName } "
139
- _LOGGER .info ("Proposing sensor '%s'" , sensor )
140
- sensors .append (DaikinEnergySensor (device , coordinator , embedded_id , management_point_type , mode , period ))
141
- else :
142
- _LOGGER .info (
143
- "Ignoring consumption data '%s', not a supported operation_mode" ,
144
- mode ,
145
- )
149
+ handle_energy_sensors (
150
+ coordinator , device , embedded_id , management_point_type , operation_modes , "electrical" , cdve , sensors
151
+ )
152
+ cdve = cdv .get ("gas" )
153
+ if cdve is not None :
154
+ handle_energy_sensors (coordinator , device , embedded_id , management_point_type , operation_modes , "gas" , cdve , sensors )
146
155
147
156
async_add_entities (sensors )
148
157
@@ -156,6 +165,7 @@ def __init__(
156
165
coordinator ,
157
166
embedded_id ,
158
167
management_point_type ,
168
+ sensor_type ,
159
169
operation_mode ,
160
170
period ,
161
171
) -> None :
@@ -167,8 +177,8 @@ def __init__(
167
177
self ._period = period
168
178
periodName = SENSOR_PERIODS [period ]
169
179
mpt = management_point_type [0 ].upper () + management_point_type [1 :]
170
- self ._attr_name = f"{ mpt } { operation_mode .capitalize ()} { periodName } Electrical Consumption"
171
- self ._attr_unique_id = f"{ self ._device .id } _{ self ._management_point_type } _electrical_ { self ._operation_mode } _{ self ._period } "
180
+ self ._attr_name = f"{ mpt } { operation_mode .capitalize ()} { periodName } { sensor_type . capitalize () } Consumption"
181
+ self ._attr_unique_id = f"{ self ._device .id } _{ self ._management_point_type } _ { sensor_type } _ { self ._operation_mode } _{ self ._period } "
172
182
self ._attr_entity_category = None
173
183
self ._attr_icon = "mdi:fire"
174
184
if operation_mode == "cooling" :
@@ -177,6 +187,7 @@ def __init__(
177
187
self ._attr_device_class = SensorDeviceClass .ENERGY
178
188
self ._attr_state_class = SensorStateClass .TOTAL_INCREASING
179
189
self ._attr_native_unit_of_measurement = UnitOfEnergy .KILO_WATT_HOUR
190
+ self ._sensor_type = sensor_type
180
191
self .update_state ()
181
192
_LOGGER .info (
182
193
"Device '%s:%s' supports sensor '%s'" ,
@@ -209,7 +220,7 @@ def sensor_value(self):
209
220
# supported operation modes
210
221
cdv = cd .get ("value" )
211
222
if cdv is not None :
212
- cdve = cdv .get ("electrical" )
223
+ cdve = cdv .get (self . _sensor_type )
213
224
if cdve is not None :
214
225
for mode in cdve :
215
226
# Only handle consumptionData for an operation mode supported by this device
@@ -218,9 +229,10 @@ def sensor_value(self):
218
229
start_index = 7 if self ._period == SENSOR_PERIOD_WEEKLY else 12
219
230
energy_value = round (sum (energy_values [start_index :]), 3 )
220
231
_LOGGER .info (
221
- "Device '%s' has energy value '%s' for mode %s %s period %s" ,
232
+ "Device '%s' has energy value '%s' for '%s' mode %s %s period %s" ,
222
233
self ._device .name ,
223
234
energy_value ,
235
+ self ._sensor_type ,
224
236
management_point_type ,
225
237
mode ,
226
238
self ._period ,
0 commit comments