Skip to content

Commit d0d1416

Browse files
authored
Merge pull request #338 from jwillemsen/jwi-gas
Support gas consumption data
2 parents a202253 + 258872f commit d0d1416

File tree

6 files changed

+3146
-39
lines changed

6 files changed

+3146
-39
lines changed

custom_components/daikin_onecta/climate.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ def get_target_temperature_step(self):
307307
step_value = None
308308
setpointdict = self.setpoint()
309309
if setpointdict is not None:
310-
step_value = setpointdict["stepValue"]
310+
step = setpointdict.get("stepValue")
311+
if step is not None:
312+
step_value = setpointdict["stepValue"]
313+
else:
314+
step_value = super().target_temperature_step
311315
_LOGGER.info(
312316
"Device '%s': %s target temperature step '%s'",
313317
self._device.name,

custom_components/daikin_onecta/sensor.py

+44-32
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ async def async_setup(hass, async_add_entities):
3737
"""
3838

3939

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+
4071
async def async_setup_entry(hass, config_entry, async_add_entities):
4172
"""Set up Daikin climate based on config_entry."""
4273
coordinator = hass.data[DAIKIN_DOMAIN][COORDINATOR]
@@ -115,34 +146,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
115146
if cdv is not None:
116147
cdve = cdv.get("electrical")
117148
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)
146155

147156
async_add_entities(sensors)
148157

@@ -156,6 +165,7 @@ def __init__(
156165
coordinator,
157166
embedded_id,
158167
management_point_type,
168+
sensor_type,
159169
operation_mode,
160170
period,
161171
) -> None:
@@ -167,8 +177,8 @@ def __init__(
167177
self._period = period
168178
periodName = SENSOR_PERIODS[period]
169179
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}"
172182
self._attr_entity_category = None
173183
self._attr_icon = "mdi:fire"
174184
if operation_mode == "cooling":
@@ -177,6 +187,7 @@ def __init__(
177187
self._attr_device_class = SensorDeviceClass.ENERGY
178188
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
179189
self._attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
190+
self._sensor_type = sensor_type
180191
self.update_state()
181192
_LOGGER.info(
182193
"Device '%s:%s' supports sensor '%s'",
@@ -209,7 +220,7 @@ def sensor_value(self):
209220
# supported operation modes
210221
cdv = cd.get("value")
211222
if cdv is not None:
212-
cdve = cdv.get("electrical")
223+
cdve = cdv.get(self._sensor_type)
213224
if cdve is not None:
214225
for mode in cdve:
215226
# Only handle consumptionData for an operation mode supported by this device
@@ -218,9 +229,10 @@ def sensor_value(self):
218229
start_index = 7 if self._period == SENSOR_PERIOD_WEEKLY else 12
219230
energy_value = round(sum(energy_values[start_index:]), 3)
220231
_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",
222233
self._device.name,
223234
energy_value,
235+
self._sensor_type,
224236
management_point_type,
225237
mode,
226238
self._period,

custom_components/daikin_onecta/water_heater.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ def get_current_operation(self):
213213
"""Return current operation ie. heat, cool, idle."""
214214
state = STATE_OFF
215215
hwtd = self.hotwatertank_data
216-
if hwtd["onOffMode"]["value"] == "on":
217-
state = STATE_HEAT_PUMP
218-
pwf = hwtd.get("powerfulMode")
219-
if pwf is not None:
220-
if pwf["value"] == "on":
221-
state = STATE_PERFORMANCE
216+
onoff = hwtd.get("onOffMode")
217+
if onoff is not None:
218+
if onoff["value"] == "on":
219+
state = STATE_HEAT_PUMP
220+
pwf = hwtd.get("powerfulMode")
221+
if pwf is not None:
222+
if pwf["value"] == "on":
223+
state = STATE_PERFORMANCE
222224
_LOGGER.debug("Device '%s' hot water tank current mode '%s'", self._device.name, state)
223225
return state
224226

0 commit comments

Comments
 (0)