From 634ee3ca690b5c452b0f2ed9eaa17cb49a4b9579 Mon Sep 17 00:00:00 2001 From: Wouter Denayer Date: Wed, 31 Mar 2021 19:59:16 +0200 Subject: [PATCH] [daikin] add energy usage day & week (#9602) * add energy usage day & week Signed-off-by: Wouter Denayer * updated readme Signed-off-by: Wouter Denayer * updated readme Signed-off-by: Wouter Denayer * removed email from @author, set log lvl to trace for parsed strings Signed-off-by: Wouter Denayer * fixed some some checkstyle warnings Signed-off-by: Wouter Denayer * addressed some checkstyle warnings Signed-off-by: Wouter Denayer * updated copyright to 2021 Signed-off-by: Wouter Denayer * made private static final Logger logger uppercase Signed-off-by: Wouter Denayer * made this logger lowercase again Signed-off-by: Wouter Denayer Co-authored-by: Wouter Denayer --- bundles/org.openhab.binding.daikin/README.md | 6 ++ .../internal/DaikinBindingConstants.java | 12 ++- .../daikin/internal/DaikinWebTargets.java | 8 ++ .../daikin/internal/api/ControlInfo.java | 4 +- .../internal/api/EnergyInfoDayAndWeek.java | 101 ++++++++++++++++++ .../daikin/internal/api/EnergyInfoYear.java | 5 +- .../daikin/internal/api/InfoParser.java | 1 - .../daikin/internal/api/SensorInfo.java | 4 +- .../internal/api/airbase/AirbaseZoneInfo.java | 4 +- .../DaikinACUnitDiscoveryService.java | 1 - .../internal/handler/DaikinAcUnitHandler.java | 49 +++++++-- .../resources/OH-INF/thing/thing-types.xml | 54 ++++++++++ 12 files changed, 231 insertions(+), 18 deletions(-) create mode 100644 bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoDayAndWeek.java diff --git a/bundles/org.openhab.binding.daikin/README.md b/bundles/org.openhab.binding.daikin/README.md index caeff8f2315..ff9d1f2e61c 100644 --- a/bundles/org.openhab.binding.daikin/README.md +++ b/bundles/org.openhab.binding.daikin/README.md @@ -48,6 +48,9 @@ For the BRP072A42 and BRP072C42: | cmpfrequency | The compressor frequency | | specialmode | The special mode currently active (OFF, STREAMER, ECO, POWERFUL, POWERFUL & STREAMER, ECO & STREAMER). Not all modes might be available on the unit. | | specialmode-powerful | Turns the powerful mode on/off for the air conditioning unit. | +| energyheatingtoday | The energy consumption when heating for today | +| energyheatingthisweek | The energy consumption when heating for this week | +| energyheatinglastweek | The energy consumption when heating for last week | | energyheatingcurrentyear-1 | The energy consumption when heating for current year January | | energyheatingcurrentyear-2 | The energy consumption when heating for current year February | | energyheatingcurrentyear-3 | The energy consumption when heating for current year March | @@ -60,6 +63,9 @@ For the BRP072A42 and BRP072C42: | energyheatingcurrentyear-10| The energy consumption when heating for current year October | | energyheatingcurrentyear-11| The energy consumption when heating for current year November | | energyheatingcurrentyear-12| The energy consumption when heating for current year December | +| energycoolingtoday | The energy consumption when cooling for today | +| energycoolingthisweek | The energy consumption when cooling for this week | +| energycoolinglastweek | The energy consumption when cooling for last week | | energycoolingcurrentyear-1 | The energy consumption when cooling for current year January | | energycoolingcurrentyear-2 | The energy consumption when cooling for current year February | | energycoolingcurrentyear-3 | The energy consumption when cooling for current year March | diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinBindingConstants.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinBindingConstants.java index 8867ffdfd22..413c1220d11 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinBindingConstants.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinBindingConstants.java @@ -49,8 +49,16 @@ public class DaikinBindingConstants { public static final String CHANNEL_CMP_FREQ = "cmpfrequency"; // Prefix and channel id format for energy - currentyear - public static final String CHANNEL_ENERGY_HEATING_CURRENTYEAR_PREFIX = "energyheatingcurrentyear"; - public static final String CHANNEL_ENERGY_COOLING_CURRENTYEAR_PREFIX = "energycoolingcurrentyear"; + public static final String CHANNEL_ENERGY_HEATING_CURRENTYEAR = "energyheatingcurrentyear"; + public static final String CHANNEL_ENERGY_COOLING_CURRENTYEAR = "energycoolingcurrentyear"; + + public static final String CHANNEL_ENERGY_HEATING_TODAY = "energyheatingtoday"; + public static final String CHANNEL_ENERGY_HEATING_THISWEEK = "energyheatingthisweek"; + public static final String CHANNEL_ENERGY_HEATING_LASTWEEK = "energyheatinglastweek"; + public static final String CHANNEL_ENERGY_COOLING_TODAY = "energycoolingtoday"; + public static final String CHANNEL_ENERGY_COOLING_THISWEEK = "energycoolingthisweek"; + public static final String CHANNEL_ENERGY_COOLING_LASTWEEK = "energycoolinglastweek"; + public static final String CHANNEL_ENERGY_STRING_FORMAT = "%s-%d"; public static final String CHANNEL_AC_SPECIALMODE = "specialmode"; diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinWebTargets.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinWebTargets.java index 7ac4f35d68f..3ebe999a07b 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinWebTargets.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinWebTargets.java @@ -27,6 +27,7 @@ import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; import org.openhab.binding.daikin.internal.api.BasicInfo; import org.openhab.binding.daikin.internal.api.ControlInfo; +import org.openhab.binding.daikin.internal.api.EnergyInfoDayAndWeek; import org.openhab.binding.daikin.internal.api.EnergyInfoYear; import org.openhab.binding.daikin.internal.api.Enums.SpecialModeKind; import org.openhab.binding.daikin.internal.api.SensorInfo; @@ -56,6 +57,7 @@ public class DaikinWebTargets { private String getSensorInfoUri; private String registerUuidUri; private String getEnergyInfoYearUri; + private String getEnergyInfoWeekUri; private String setSpecialModeUri; private String setAirbaseControlInfoUri; @@ -83,6 +85,7 @@ public class DaikinWebTargets { getSensorInfoUri = baseUri + "aircon/get_sensor_info"; registerUuidUri = baseUri + "common/register_terminal"; getEnergyInfoYearUri = baseUri + "aircon/get_year_power_ex"; + getEnergyInfoWeekUri = baseUri + "aircon/get_week_power_ex"; setSpecialModeUri = baseUri + "aircon/set_special_mode"; // Daikin Airbase API @@ -128,6 +131,11 @@ public class DaikinWebTargets { return EnergyInfoYear.parse(response); } + public EnergyInfoDayAndWeek getEnergyInfoDayAndWeek() throws DaikinCommunicationException { + String response = invoke(getEnergyInfoWeekUri); + return EnergyInfoDayAndWeek.parse(response); + } + public boolean setSpecialMode(SpecialModeKind specialModeKind, boolean state) throws DaikinCommunicationException { Map queryParams = new HashMap<>(); queryParams.put("spmode_kind", String.valueOf(specialModeKind.getValue())); diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/ControlInfo.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/ControlInfo.java index 48150e3e228..1440acb985f 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/ControlInfo.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/ControlInfo.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class ControlInfo { - private static final Logger logger = LoggerFactory.getLogger(ControlInfo.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ControlInfo.class); public String ret = ""; public boolean power = false; @@ -50,7 +50,7 @@ public class ControlInfo { } public static ControlInfo parse(String response) { - logger.debug("Parsing string: \"{}\"", response); + LOGGER.debug("Parsing string: \"{}\"", response); Map responseMap = InfoParser.parse(response); diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoDayAndWeek.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoDayAndWeek.java new file mode 100644 index 00000000000..88995529858 --- /dev/null +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoDayAndWeek.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.daikin.internal.api; + +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Holds information from the get_week_power_ex call. + * + * @author Wouter Denayer - Initial contribution + * + */ +@NonNullByDefault +public class EnergyInfoDayAndWeek { + public Optional energyHeatingToday = Optional.empty(); + public Optional energyHeatingThisWeek = Optional.empty(); + public Optional energyHeatingLastWeek = Optional.empty(); + public Optional energyCoolingToday = Optional.empty(); + public Optional energyCoolingThisWeek = Optional.empty(); + public Optional energyCoolingLastWeek = Optional.empty(); + + private static final Logger logger = LoggerFactory.getLogger(EnergyInfoDayAndWeek.class); + + private EnergyInfoDayAndWeek() { + } + + public static EnergyInfoDayAndWeek parse(String response) { + EnergyInfoDayAndWeek info = new EnergyInfoDayAndWeek(); + + logger.trace("Parsing string: \"{}\"", response); + + // /aircon/get_week_power_ex + // ret=OK,s_dayw=0,week_heat=1/1/1/1/1/5/2/1/1/1/1/2/1/1,week_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0 + // week_heat=////... + Map responseMap = Arrays.asList(response.split(",")).stream().filter(kv -> kv.contains("=")) + .map(kv -> { + String[] keyValue = kv.split("="); + String key = keyValue[0]; + String value = keyValue.length > 1 ? keyValue[1] : ""; + return new String[] { key, value }; + }).collect(Collectors.toMap(x -> x[0], x -> x[1])); + + if (responseMap.get("ret") != null && ("OK".equals(responseMap.get("ret")))) { + Optional dayOfWeek = Optional.ofNullable(responseMap.get("s_dayw")) + .flatMap(value -> InfoParser.parseInt(value)); + + if (dayOfWeek.isPresent()) { + // Daikin API week starts on Sunday, ours on Monday + int thisWeekLastDayIndex = (dayOfWeek.get().intValue() == 0) ? 7 : dayOfWeek.get().intValue(); + + // get the heating info + String[] heatingValues = responseMap.get("week_heat").split("/"); + info.energyHeatingToday = Optional.of(Double.parseDouble(heatingValues[0]) / 10); + double thisWeekEnergy = 0; + for (int i = 0; i < thisWeekLastDayIndex; i += 1) { + thisWeekEnergy += Integer.parseInt(heatingValues[i]); + } + double previousWeekEnergy = 0; + for (int i = thisWeekLastDayIndex; i < thisWeekLastDayIndex + 7; i += 1) { + previousWeekEnergy += Integer.parseInt(heatingValues[i]); + } + info.energyHeatingThisWeek = Optional.of(thisWeekEnergy / 10); + info.energyHeatingLastWeek = Optional.of(previousWeekEnergy / 10); + + // get the cooling info + String[] coolingValues = responseMap.get("week_cool").split("/"); + info.energyCoolingToday = Optional.of(Double.parseDouble(coolingValues[0]) / 10); + thisWeekEnergy = 0; + for (int i = 0; i < thisWeekLastDayIndex; i += 1) { + thisWeekEnergy += Integer.parseInt(coolingValues[i]); + } + previousWeekEnergy = 0; + for (int i = thisWeekLastDayIndex; i < thisWeekLastDayIndex + 7; i += 1) { + previousWeekEnergy += Integer.parseInt(coolingValues[i]); + } + info.energyCoolingThisWeek = Optional.of(thisWeekEnergy / 10); + info.energyCoolingLastWeek = Optional.of(previousWeekEnergy / 10); + } + } else { + logger.debug("did not receive 'ret=OK' from adapter"); + } + return info; + } +} diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoYear.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoYear.java index 58b9bfdf1fa..2d4b126381f 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoYear.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/EnergyInfoYear.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class EnergyInfoYear { - private static final Logger logger = LoggerFactory.getLogger(EnergyInfoYear.class); + private static final Logger LOGGER = LoggerFactory.getLogger(EnergyInfoYear.class); public Optional energyHeatingThisYear = Optional.empty(); @@ -37,7 +37,8 @@ public class EnergyInfoYear { } public static EnergyInfoYear parse(String response) { - logger.debug("Parsing string: \"{}\"", response); + + LOGGER.trace("Parsing string: \"{}\"", response); Map responseMap = InfoParser.parse(response); diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/InfoParser.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/InfoParser.java index 429e6933343..f91eb401595 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/InfoParser.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/InfoParser.java @@ -67,7 +67,6 @@ public class InfoParser { } try { return Optional.of(Stream.of(value.split("/")).map(val -> Integer.parseInt(val)).toArray(Integer[]::new)); - } catch (NumberFormatException e) { return Optional.empty(); } diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/SensorInfo.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/SensorInfo.java index 101601a0cf5..d276d93d0da 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/SensorInfo.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/SensorInfo.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class SensorInfo { - private static final Logger logger = LoggerFactory.getLogger(SensorInfo.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SensorInfo.class); public Optional indoortemp = Optional.empty(); public Optional indoorhumidity = Optional.empty(); @@ -38,7 +38,7 @@ public class SensorInfo { } public static SensorInfo parse(String response) { - logger.debug("Parsing string: \"{}\"", response); + LOGGER.debug("Parsing string: \"{}\"", response); Map responseMap = InfoParser.parse(response); diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java index 0ddb46b444c..9c000667e16 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java @@ -48,10 +48,10 @@ public class AirbaseZoneInfo { info.zonenames = Optional.ofNullable(responseMap.get("zone_name")).orElse(""); String zoneinfo = Optional.ofNullable(responseMap.get("zone_onoff")).orElse(""); - String[] Zones = zoneinfo.split("%3b"); + String[] zones = zoneinfo.split("%3b"); for (int i = 1; i < 9; i++) - info.zone[i] = "1".equals(Zones[i - 1]); + info.zone[i] = "1".equals(zones[i - 1]); return info; } diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java index 6860c8159d0..b9c6382379c 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java @@ -180,7 +180,6 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService { thingDiscovered(result); return true; } - } catch (Exception e) { return false; } diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java index b4720e93269..6a88283df4d 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java @@ -25,6 +25,7 @@ import org.openhab.binding.daikin.internal.DaikinCommunicationException; import org.openhab.binding.daikin.internal.DaikinDynamicStateDescriptionProvider; import org.openhab.binding.daikin.internal.DaikinWebTargets; import org.openhab.binding.daikin.internal.api.ControlInfo; +import org.openhab.binding.daikin.internal.api.EnergyInfoDayAndWeek; import org.openhab.binding.daikin.internal.api.EnergyInfoYear; import org.openhab.binding.daikin.internal.api.Enums.FanMovement; import org.openhab.binding.daikin.internal.api.Enums.FanSpeed; @@ -32,6 +33,7 @@ import org.openhab.binding.daikin.internal.api.Enums.HomekitMode; import org.openhab.binding.daikin.internal.api.Enums.Mode; import org.openhab.binding.daikin.internal.api.Enums.SpecialModeKind; import org.openhab.binding.daikin.internal.api.SensorInfo; +import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StringType; @@ -49,8 +51,10 @@ import org.slf4j.LoggerFactory; * Handles communicating with a Daikin air conditioning unit. * * @author Tim Waterhouse - Initial Contribution - * @author Paul Smedley - Modifications to support Airbase Controllers + * @author Paul Smedley - Modifications to support Airbase Controllers * @author Lukas Agethen - Added support for Energy Year reading, compressor frequency and powerful mode + * @author Wouter Denayer - Added to support for weekly & daily energy reading + * */ @NonNullByDefault public class DaikinAcUnitHandler extends DaikinBaseHandler { @@ -118,17 +122,37 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler { EnergyInfoYear energyInfoYear = webTargets.getEnergyInfoYear(); if (energyInfoYear.energyHeatingThisYear.isPresent()) { - updateEnergyYearChannel(DaikinBindingConstants.CHANNEL_ENERGY_HEATING_CURRENTYEAR_PREFIX, + updateEnergyYearChannel(DaikinBindingConstants.CHANNEL_ENERGY_HEATING_CURRENTYEAR, energyInfoYear.energyHeatingThisYear); } if (energyInfoYear.energyCoolingThisYear.isPresent()) { - updateEnergyYearChannel(DaikinBindingConstants.CHANNEL_ENERGY_COOLING_CURRENTYEAR_PREFIX, + updateEnergyYearChannel(DaikinBindingConstants.CHANNEL_ENERGY_COOLING_CURRENTYEAR, energyInfoYear.energyCoolingThisYear); } } catch (DaikinCommunicationException e) { // Suppress any error if energy info is not supported. logger.debug("getEnergyInfoYear() error: {}", e.getMessage()); } + + try { + EnergyInfoDayAndWeek energyInfoDayAndWeek = webTargets.getEnergyInfoDayAndWeek(); + + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_HEATING_TODAY, + energyInfoDayAndWeek.energyHeatingToday); + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_HEATING_THISWEEK, + energyInfoDayAndWeek.energyHeatingThisWeek); + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_HEATING_LASTWEEK, + energyInfoDayAndWeek.energyHeatingLastWeek); + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_COOLING_TODAY, + energyInfoDayAndWeek.energyCoolingToday); + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_COOLING_THISWEEK, + energyInfoDayAndWeek.energyCoolingThisWeek); + updateEnergyDayAndWeekChannel(DaikinBindingConstants.CHANNEL_ENERGY_COOLING_LASTWEEK, + energyInfoDayAndWeek.energyCoolingLastWeek); + } catch (DaikinCommunicationException e) { + // Suppress any error if energy info is not supported. + logger.debug("getEnergyInfoDayAndWeek() error: {}", e.getMessage()); + } } @Override @@ -243,12 +267,12 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler { /** * Updates energy year channels. Values are provided in hundreds of Watt * - * @param channelPrefix + * @param channel * @param maybePower */ - protected void updateEnergyYearChannel(String channelPrefix, Optional maybePower) { + protected void updateEnergyYearChannel(String channel, Optional maybePower) { IntStream.range(1, 13).forEach(i -> updateState( - String.format(DaikinBindingConstants.CHANNEL_ENERGY_STRING_FORMAT, channelPrefix, i), + String.format(DaikinBindingConstants.CHANNEL_ENERGY_STRING_FORMAT, channel, i), maybePower. map( t -> new QuantityType<>(BigDecimal.valueOf(t[i - 1].longValue(), 1), Units.KILOWATT_HOUR)) .orElse(UnDefType.UNDEF)) @@ -256,6 +280,19 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler { ); } + /** + * + * @param channel + * @param maybePower + */ + protected void updateEnergyDayAndWeekChannel(String channel, Optional maybePower) { + if (maybePower.isPresent()) { + updateState(channel, + maybePower. map(t -> new QuantityType<>(new DecimalType(t), Units.KILOWATT_HOUR)) + .orElse(UnDefType.UNDEF)); + } + } + @Override protected void registerUuid(@Nullable String key) { if (key == null) { diff --git a/bundles/org.openhab.binding.daikin/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.daikin/src/main/resources/OH-INF/thing/thing-types.xml index d616404007a..db54c426857 100644 --- a/bundles/org.openhab.binding.daikin/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.daikin/src/main/resources/OH-INF/thing/thing-types.xml @@ -21,6 +21,9 @@ + + + @@ -33,6 +36,9 @@ + + + @@ -174,6 +180,54 @@ + + Number:Energy + + The energy usage for heating today + Energy + + + + + Number:Energy + + The energy usage for heating this week + Energy + + + + + Number:Energy + + The energy usage for heating last week + Energy + + + + + Number:Energy + + The energy usage for cooling today + Energy + + + + + Number:Energy + + The energy usage for cooling this week + Energy + + + + + Number:Energy + + The energy usage for cooling last week + Energy + + + Number:Dimensionless