Skip to content

Commit

Permalink
[daikin] Add Energy, compressor frequency and special mode channels (o…
Browse files Browse the repository at this point in the history
…penhab#7708)

* [daikin] Add Energy, compressor frequency and special mode channels

openhab#6980: Add compressor frequency channel
openhab#6115: Add energy current year channels

* Update small typos and code refactoring as suggested by cpmeister
* Update small typos and added units where possible

Signed-off-by: Lukas Agethen <[email protected]>
  • Loading branch information
LukasA83 authored and andrewfg committed Aug 31, 2020
1 parent 56603e6 commit 159d553
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 75 deletions.
27 changes: 27 additions & 0 deletions bundles/org.openhab.binding.daikin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ For the BRP072A42 and BRP072C42:
| homekitmode | A mode that is compatible with homekit/alexa/google home (off, auto, heat, cool). Not tested for BRP069B41 |
| fanspeed | The fan speed set for the unit (AUTO, SILENCE, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5) |
| fandir | The fan blade direction (STOPPED, VERTICAL, HORIZONTAL, VERTICAL_AND_HORIZONTAL) |
| 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. |
| 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 |
| energyheatingcurrentyear-4 | The energy consumption when heating for current year April |
| energyheatingcurrentyear-5 | The energy consumption when heating for current year May |
| energyheatingcurrentyear-6 | The energy consumption when heating for current year June |
| energyheatingcurrentyear-7 | The energy consumption when heating for current year July |
| energyheatingcurrentyear-8 | The energy consumption when heating for current year August |
| energyheatingcurrentyear-9 | The energy consumption when heating for current year September |
| 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 |
| 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 |
| energycoolingcurrentyear-4 | The energy consumption when cooling for current year April |
| energycoolingcurrentyear-5 | The energy consumption when cooling for current year May |
| energycoolingcurrentyear-6 | The energy consumption when cooling for current year June |
| energycoolingcurrentyear-7 | The energy consumption when cooling for current year July |
| energycoolingcurrentyear-8 | The energy consumption when cooling for current year August |
| energycoolingcurrentyear-9 | The energy consumption when cooling for current year September |
| energycoolingcurrentyear-10| The energy consumption when cooling for current year October |
| energycoolingcurrentyear-11| The energy consumption when cooling for current year November |
| energycoolingcurrentyear-12| The energy consumption when cooling for current year December |

For the BRP15B61:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public class DaikinBindingConstants {
public static final String CHANNEL_AC_FAN_SPEED = "fanspeed";
public static final String CHANNEL_AC_FAN_DIR = "fandir";
public static final String CHANNEL_HUMIDITY = "humidity";
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_STRING_FORMAT = "%s-%d";

public static final String CHANNEL_AC_SPECIALMODE = "specialmode";
public static final String CHANNEL_AC_SPECIALMODE_POWERFUL = "specialmode-powerful";

// additional channels for Airbase Controller
public static final String CHANNEL_AIRBASE_AC_FAN_SPEED = "airbasefanspeed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package org.openhab.binding.daikin.internal;

import java.io.IOException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* Exception for when an unexpected response is received from the Daikin controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.openhab.binding.daikin.internal;

import java.io.IOException;
import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -23,6 +22,9 @@
*/
@NonNullByDefault
public class DaikinCommunicationForbiddenException extends DaikinCommunicationException {

private static final long serialVersionUID = 1L;

public DaikinCommunicationForbiddenException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
package org.openhab.binding.daikin.internal;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -29,15 +28,16 @@
import org.eclipse.smarthome.io.net.http.HttpUtil;
import org.openhab.binding.daikin.internal.api.BasicInfo;
import org.openhab.binding.daikin.internal.api.ControlInfo;
import org.openhab.binding.daikin.internal.api.Enums.SpecialModeKind;
import org.openhab.binding.daikin.internal.api.SensorInfo;
import org.openhab.binding.daikin.internal.api.EnergyInfoYear;
import org.openhab.binding.daikin.internal.api.airbase.AirbaseBasicInfo;
import org.openhab.binding.daikin.internal.api.airbase.AirbaseControlInfo;
import org.openhab.binding.daikin.internal.api.airbase.AirbaseModelInfo;
import org.openhab.binding.daikin.internal.api.airbase.AirbaseZoneInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* Handles performing the actual HTTP requests for communicating with Daikin air conditioning units.
*
Expand All @@ -55,6 +55,9 @@ public class DaikinWebTargets {
private String getControlInfoUri;
private String getSensorInfoUri;
private String registerUuidUri;
private String getEnergyInfoYearUri;
private String setSpecialModeUri;

private String setAirbaseControlInfoUri;
private String getAirbaseControlInfoUri;
private String getAirbaseSensorInfoUri;
Expand All @@ -68,7 +71,8 @@ public class DaikinWebTargets {

private Logger logger = LoggerFactory.getLogger(DaikinWebTargets.class);

public DaikinWebTargets(@Nullable HttpClient httpClient, @Nullable String host, @Nullable Boolean secure, @Nullable String uuid) {
public DaikinWebTargets(@Nullable HttpClient httpClient, @Nullable String host, @Nullable Boolean secure,
@Nullable String uuid) {
this.httpClient = httpClient;
this.uuid = uuid;

Expand All @@ -78,6 +82,8 @@ public DaikinWebTargets(@Nullable HttpClient httpClient, @Nullable String host,
getControlInfoUri = baseUri + "aircon/get_control_info";
getSensorInfoUri = baseUri + "aircon/get_sensor_info";
registerUuidUri = baseUri + "common/register_terminal";
getEnergyInfoYearUri = baseUri + "aircon/get_year_power_ex";
setSpecialModeUri = baseUri + "aircon/set_special_mode";

// Daikin Airbase API
getAirbaseBasicInfoUri = baseUri + "skyfi/common/basic_info";
Expand Down Expand Up @@ -117,6 +123,19 @@ public void registerUuid(String key) throws DaikinCommunicationException {
logger.debug("registerUuid result: {}", response);
}

public EnergyInfoYear getEnergyInfoYear() throws DaikinCommunicationException {
String response = invoke(getEnergyInfoYearUri);
return EnergyInfoYear.parse(response);
}

public boolean setSpecialMode(SpecialModeKind specialModeKind, boolean state) throws DaikinCommunicationException {
Map<String, String> queryParams = new HashMap<>();
queryParams.put("spmode_kind",String.valueOf(specialModeKind.getValue()));
queryParams.put("set_spmode", state ? "1" : "0");
String response = invoke(setSpecialModeUri, queryParams);
return !response.contains("ret=OK");
}

// Daikin Airbase API
public AirbaseControlInfo getAirbaseControlInfo() throws DaikinCommunicationException {
String response = invoke(getAirbaseControlInfoUri);
Expand Down Expand Up @@ -188,9 +207,8 @@ private String invoke(String uri, Map<String, String> params) throws DaikinCommu

private String executeUrl(String url) throws DaikinCommunicationException {
try {
Request request = httpClient.newRequest(url)
.method(HttpMethod.GET)
.timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS);
Request request = httpClient.newRequest(url).method(HttpMethod.GET).timeout(TIMEOUT_MS,
TimeUnit.MILLISECONDS);
if (uuid != null) {
request.header("X-Daikin-uuid", uuid);
logger.debug("Header: X-Daikin-uuid: {}", uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.daikin.internal.api.InfoParser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;

import org.openhab.binding.daikin.internal.api.Enums.FanMovement;
import org.openhab.binding.daikin.internal.api.Enums.FanSpeed;
import org.openhab.binding.daikin.internal.api.Enums.Mode;
import org.openhab.binding.daikin.internal.api.Enums.SpecialMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -44,6 +44,7 @@ public class ControlInfo {
public FanMovement fanMovement = FanMovement.STOPPED;
/* Not supported by all units. Sets the target humidity for dehumidifying. */
public Optional<Integer> targetHumidity = Optional.empty();
public SpecialMode specialMode = SpecialMode.UNKNOWN;

private ControlInfo() {
}
Expand All @@ -65,6 +66,8 @@ public static ControlInfo parse(String response) {
.map(value -> FanMovement.fromValue(value)).orElse(FanMovement.STOPPED);
info.targetHumidity = Optional.ofNullable(responseMap.get("shum")).flatMap(value -> InfoParser.parseInt(value));

info.specialMode = Optional.ofNullable(responseMap.get("adv")).map(value -> SpecialMode.fromValue(value))
.orElse(SpecialMode.UNKNOWN);
return info;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2010-2020 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.Map;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Holds information from the get_year_power_ex call.
*
* @author Lukas Agethen - Initial contribution
*
*/
@NonNullByDefault
public class EnergyInfoYear {
private static final Logger logger = LoggerFactory.getLogger(EnergyInfoYear.class);

public Optional<Integer[]> energyHeatingThisYear = Optional.empty();

public Optional<Integer[]> energyCoolingThisYear = Optional.empty();

private EnergyInfoYear() {
}

public static EnergyInfoYear parse(String response) {
logger.debug("Parsing string: \"{}\"", response);

Map<String, String> responseMap = InfoParser.parse(response);

EnergyInfoYear info = new EnergyInfoYear();
info.energyHeatingThisYear = Optional.ofNullable(responseMap.get("curr_year_heat"))
.flatMap(value -> InfoParser.parseArrayofInt(value, 12));

info.energyCoolingThisYear = Optional.ofNullable(responseMap.get("curr_year_cool"))
.flatMap(value -> InfoParser.parseArrayofInt(value, 12));

return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
package org.openhab.binding.daikin.internal.api;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Container class for enums related to Daikin A/C systems
*
* @author Tim Waterhouse <[email protected]> - Initial contribution
* @author Lukas Agethen - Add special modes
*
*/
@NonNullByDefault
Expand Down Expand Up @@ -138,4 +138,75 @@ public String getValue() {
return value;
}
}

public enum SpecialMode {
STREAMER("13"),
ECO("12"),
POWERFUL("2"),
POWERFUL_STREAMER("2/13"),
ECO_STREAMER("12/13"),
OFF(""),
UNKNOWN("??");

private static final Logger LOGGER = LoggerFactory.getLogger(SpecialMode.class);
private final String value;

SpecialMode(String value) {
this.value = value;
}

public String getValue() {
return value;
}

public boolean isPowerfulActive() {
return this.equals(POWERFUL) || this.equals(POWERFUL_STREAMER);
}

public boolean isUndefined() {
return this.equals(UNKNOWN);
}

public static SpecialMode fromValue(String value) {
for (SpecialMode m : SpecialMode.values()) {
if (m.getValue().equals(value)) {
return m;
}
}
LOGGER.debug("Unexpected SpecialMode value of \"{}\"", value);

// Default to UNKNOWN
return UNKNOWN;
}
}

public enum SpecialModeKind {
UNKNOWN(-1),
STREAMER(0),
POWERFUL(1),
ECO(2);

private static final Logger LOGGER = LoggerFactory.getLogger(SpecialModeKind.class);
private final int value;

SpecialModeKind(int value) {
this.value = value;
}

public int getValue() {
return value;
}

public static SpecialModeKind fromValue(int value) {
for (SpecialModeKind m : SpecialModeKind.values()) {
if (m.getValue() == value) {
return m;
}
}
LOGGER.debug("Unexpected SpecialModeKind value of \"{}\"", value);

// Default to UNKNOWN
return UNKNOWN;
}
}
}
Loading

0 comments on commit 159d553

Please sign in to comment.