Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillemsen committed Nov 13, 2024
2 parents 2a9c03d + 26e705d commit f15b1a0
Show file tree
Hide file tree
Showing 7 changed files with 3,147 additions and 40 deletions.
6 changes: 5 additions & 1 deletion custom_components/daikin_onecta/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ def get_target_temperature_step(self):
step_value = None
setpointdict = self.setpoint()
if setpointdict is not None:
step_value = setpointdict["stepValue"]
step = setpointdict.get("stepValue")
if step is not None:
step_value = setpointdict["stepValue"]
else:
step_value = super().target_temperature_step
_LOGGER.info(
"Device '%s': %s target temperature step '%s'",
self._device.name,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/daikin_onecta/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/jwillemsen/daikin_onecta/issues",
"requirements": [],
"version": "4.1.20"
"version": "4.1.21"
}
76 changes: 44 additions & 32 deletions custom_components/daikin_onecta/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ async def async_setup(hass, async_add_entities):
"""


def handle_energy_sensors(coordinator, device, embedded_id, management_point_type, operation_modes, sensor_type, cdve, sensors):
_LOGGER.info("Device '%s' provides '%s'", device.name, sensor_type)
for mode in cdve:
# Only handle consumptionData for an operation mode supported by this device
if mode in operation_modes:
_LOGGER.info(
"Device '%s' provides mode %s %s",
device.name,
management_point_type,
mode,
)
for period in cdve[mode]:
_LOGGER.info(
"Device '%s:%s' provides mode %s %s supports period %s",
device.name,
embedded_id,
management_point_type,
mode,
period,
)
periodName = SENSOR_PERIODS[period]
sensor = f"{device.name} {sensor_type} {management_point_type} {mode} {periodName}"
_LOGGER.info("Proposing sensor '%s'", sensor)
sensors.append(DaikinEnergySensor(device, coordinator, embedded_id, management_point_type, sensor_type, mode, period))
else:
_LOGGER.info(
"Ignoring consumption data '%s', not a supported operation_mode",
mode,
)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Daikin climate based on config_entry."""
coordinator = hass.data[DAIKIN_DOMAIN][COORDINATOR]
Expand Down Expand Up @@ -115,34 +146,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
if cdv is not None:
cdve = cdv.get("electrical")
if cdve is not None:
_LOGGER.info("Device '%s' provides electrical", device.name)
for mode in cdve:
# Only handle consumptionData for an operation mode supported by this device
if mode in operation_modes:
_LOGGER.info(
"Device '%s' provides mode %s %s",
device.name,
management_point_type,
mode,
)
for period in cdve[mode]:
_LOGGER.info(
"Device '%s:%s' provides mode %s %s supports period %s",
device.name,
embedded_id,
management_point_type,
mode,
period,
)
periodName = SENSOR_PERIODS[period]
sensor = f"{device.name} {management_point_type} {mode} {periodName}"
_LOGGER.info("Proposing sensor '%s'", sensor)
sensors.append(DaikinEnergySensor(device, coordinator, embedded_id, management_point_type, mode, period))
else:
_LOGGER.info(
"Ignoring consumption data '%s', not a supported operation_mode",
mode,
)
handle_energy_sensors(
coordinator, device, embedded_id, management_point_type, operation_modes, "electrical", cdve, sensors
)
cdve = cdv.get("gas")
if cdve is not None:
handle_energy_sensors(coordinator, device, embedded_id, management_point_type, operation_modes, "gas", cdve, sensors)

async_add_entities(sensors)

Expand All @@ -156,6 +165,7 @@ def __init__(
coordinator,
embedded_id,
management_point_type,
sensor_type,
operation_mode,
period,
) -> None:
Expand All @@ -167,8 +177,8 @@ def __init__(
self._period = period
periodName = SENSOR_PERIODS[period]
mpt = management_point_type[0].upper() + management_point_type[1:]
self._attr_name = f"{mpt} {operation_mode.capitalize()} {periodName} Electrical Consumption"
self._attr_unique_id = f"{self._device.id}_{self._management_point_type}_electrical_{self._operation_mode}_{self._period}"
self._attr_name = f"{mpt} {operation_mode.capitalize()} {periodName} {sensor_type.capitalize()} Consumption"
self._attr_unique_id = f"{self._device.id}_{self._management_point_type}_{sensor_type}_{self._operation_mode}_{self._period}"
self._attr_entity_category = None
self._attr_icon = "mdi:fire"
if operation_mode == "cooling":
Expand All @@ -177,6 +187,7 @@ def __init__(
self._attr_device_class = SensorDeviceClass.ENERGY
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
self._attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
self._sensor_type = sensor_type
self.update_state()
_LOGGER.info(
"Device '%s:%s' supports sensor '%s'",
Expand Down Expand Up @@ -209,7 +220,7 @@ def sensor_value(self):
# supported operation modes
cdv = cd.get("value")
if cdv is not None:
cdve = cdv.get("electrical")
cdve = cdv.get(self._sensor_type)
if cdve is not None:
for mode in cdve:
# Only handle consumptionData for an operation mode supported by this device
Expand All @@ -218,9 +229,10 @@ def sensor_value(self):
start_index = 7 if self._period == SENSOR_PERIOD_WEEKLY else 12
energy_value = round(sum(energy_values[start_index:]), 3)
_LOGGER.info(
"Device '%s' has energy value '%s' for mode %s %s period %s",
"Device '%s' has energy value '%s' for '%s' mode %s %s period %s",
self._device.name,
energy_value,
self._sensor_type,
management_point_type,
mode,
self._period,
Expand Down
14 changes: 8 additions & 6 deletions custom_components/daikin_onecta/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ def get_current_operation(self):
"""Return current operation ie. heat, cool, idle."""
state = STATE_OFF
hwtd = self.hotwatertank_data
if hwtd["onOffMode"]["value"] == "on":
state = STATE_HEAT_PUMP
pwf = hwtd.get("powerfulMode")
if pwf is not None:
if pwf["value"] == "on":
state = STATE_PERFORMANCE
onoff = hwtd.get("onOffMode")
if onoff is not None:
if onoff["value"] == "on":
state = STATE_HEAT_PUMP
pwf = hwtd.get("powerfulMode")
if pwf is not None:
if pwf["value"] == "on":
state = STATE_PERFORMANCE
_LOGGER.debug("Device '%s' hot water tank current mode '%s'", self._device.name, state)
return state

Expand Down
Loading

0 comments on commit f15b1a0

Please sign in to comment.