Skip to content

Commit

Permalink
[innogysmarthome] Battery state of RST2 is now supported (#8375)
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strohschein <[email protected]>
  • Loading branch information
Novanic authored Aug 31, 2020
1 parent 3842672 commit 8f20990
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ public class InnogyBindingConstants {
public static final String CLIENT_SECRET_INNOGY_SMARTHOME = "no secret";
public static final String REDIRECT_URL_INNOGY_SMARTHOME = "https://www.openhab.org/oauth/innogy/innogy-smarthome.html";

// Bridge config parameters
public static final String CONFIG_BRAND = "brand";

public static final String CONFIG_AUTH_CODE = "authcode";
public static final String CONFIG_ACCESS_TOKEN = "accesstoken";
public static final String CONFIG_REFRESH_TOKEN = "refreshtoken";
public static final String CONFIG_WEBSOCKET_IDLE_TIMEOUT = "websocketidletimeout";

public static final long REINITIALIZE_DELAY_SECONDS = 30;
public static final long REINITIALIZE_RETRY_SECONDS = 60;
Expand Down Expand Up @@ -75,7 +69,6 @@ public class InnogyBindingConstants {
public static final String PROPERTY_BACKEND_CONNECTION_MONITORED = "Backend connection monitored";
public static final String PROPERTY_RFCOM_FAILURE_NOTIFICATION = "RFComm failure notification";
public static final String PROPERTY_DISPLAY_CURRENT_TEMPERATURE = "Display current temperature";
public static final String PROPERTY_UNDERLYING_DEVICE_IDS = "Underlying device IDs (thermostats)";
public static final String PROPERTY_METER_ID = "Meter ID";
public static final String PROPERTY_METER_FIRMWARE_VERSION = "Meter firmware version";

Expand Down Expand Up @@ -113,6 +106,10 @@ public class InnogyBindingConstants {
DEVICE_GENERATION_METER, DEVICE_SMART_METER, DEVICE_TWO_WAY_METER)
.collect(Collectors.toSet()));

public static final Set<String> BATTERY_POWERED_DEVICES = Collections
.unmodifiableSet(Stream.of(DEVICE_RST, DEVICE_RST2, DEVICE_WRT, DEVICE_WDS, DEVICE_WSD, DEVICE_WSD2,
DEVICE_WMD, DEVICE_WMDO, DEVICE_WSC2, DEVICE_BRC8).collect(Collectors.toSet()));

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final ThingTypeUID THING_TYPE_PSS = new ThingTypeUID(BINDING_ID, DEVICE_PSS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
*/
package org.openhab.binding.innogysmarthome.internal.client;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -28,19 +23,13 @@
@NonNullByDefault
public final class Constants {

// devices
public static final Set<String> BATTERY_POWERED_DEVICES = Collections.unmodifiableSet(
Stream.of("RST", "WRT", "WDS", "WSD", "WSD2", "WMD", "WMDO", "WSC2", "BRC8").collect(Collectors.toSet()));

// API URLs
public static final String API_HOST = "api.services-smarthome.de";
public static final String AUTH_HOST = "auth.services-smarthome.de";
public static final String API_VERSION = "1.1";
public static final String API_URL_BASE = "https://" + API_HOST + "/API/" + API_VERSION;
public static final String API_URL_TOKEN = "https://" + AUTH_HOST + "/AUTH/token";

public static final String API_URL_CHECK_CONNECTION = API_URL_BASE + "/desc/device/SHC.RWE/1.0/event/StateChanged";
public static final String API_URL_INITIALIZE = API_URL_BASE + "/initialize";
public static final String API_URL_STATUS = API_URL_BASE + "/status";

public static final String API_URL_DEVICE = API_URL_BASE + "/device";
Expand All @@ -56,12 +45,8 @@ public final class Constants {

public static final String API_URL_MESSAGE = API_URL_BASE + "/message";

public static final String API_URL_EVENTS = "wss://" + API_HOST + "/API/" + API_VERSION + "/events?token={token}";
public static final String API_URL_ACTION = API_URL_BASE + "/action";

// others
public static final String FORMAT_DATETIME = "dd.MM.yyyy HH:mm:ss";

private Constants() {
// Constants class
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.binding.innogysmarthome.internal.client;

import static org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants.*;
import static org.openhab.binding.innogysmarthome.internal.client.Constants.*;

import java.io.IOException;
Expand Down Expand Up @@ -39,6 +40,7 @@
import org.eclipse.smarthome.core.auth.client.oauth2.OAuthClientService;
import org.eclipse.smarthome.core.auth.client.oauth2.OAuthException;
import org.eclipse.smarthome.core.auth.client.oauth2.OAuthResponseException;
import org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants;
import org.openhab.binding.innogysmarthome.internal.client.entity.StatusResponse;
import org.openhab.binding.innogysmarthome.internal.client.entity.action.Action;
import org.openhab.binding.innogysmarthome.internal.client.entity.action.ShutterAction;
Expand Down Expand Up @@ -462,7 +464,7 @@ public List<Device> getFullDevices() throws IOException, ApiException, Authentic
// DEVICES
final List<Device> deviceList = getDevices();
for (final Device d : deviceList) {
if (BATTERY_POWERED_DEVICES.contains(d.getType())) {
if (InnogyBindingConstants.BATTERY_POWERED_DEVICES.contains(d.getType())) {
d.setIsBatteryPowered(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.innogysmarthome.internal.client.entity.device;

import static org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -29,30 +31,6 @@
*/
public class Device {

public static final String DEVICE_TYPE_SHC = "SHC";
public static final String DEVICE_TYPE_SHCA = "SHCA";
public static final String DEVICE_TYPE_ANALOG_METER = "AnalogMeter";
public static final String DEVICE_TYPE_BRC8 = "BRC8";
public static final String DEVICE_TYPE_GENERATION_METER = "GenerationMeter";
public static final String DEVICE_TYPE_ISC2 = "ISC2";
public static final String DEVICE_TYPE_ISD2 = "ISD2";
public static final String DEVICE_TYPE_ISR2 = "ISR2";
public static final String DEVICE_TYPE_ISS2 = "ISS2";
public static final String DEVICE_TYPE_PSD = "PSD";
public static final String DEVICE_TYPE_PSS = "PSS";
public static final String DEVICE_TYPE_PSSO = "PSSO";
public static final String DEVICE_TYPE_RST = "RST";
public static final String DEVICE_TYPE_SMARTMETER = "SmartMeter";
public static final String DEVICE_TYPE_TWO_WAY_METER = "TwoWayMeter";
public static final String DEVICE_TYPE_VARIABLE_ACTUATOR = "VariableActuator";
public static final String DEVICE_TYPE_WDS = "WDS";
public static final String DEVICE_TYPE_WMD = "WMD";
public static final String DEVICE_TYPE_WMDO = "WMDO";
public static final String DEVICE_TYPE_WRT = "WRT";
public static final String DEVICE_TYPE_WSC2 = "WSC2";
public static final String DEVICE_TYPE_WSD = "WSD";
public static final String DEVICE_TYPE_WSD2 = "WSD2";

public static final String DEVICE_MANUFACTURER_RWE = "RWE";
public static final String DEVICE_MANUFACTURER_INNOGY = "innogy";

Expand Down Expand Up @@ -474,7 +452,7 @@ public boolean hasMessages() {
* @return
*/
public boolean isController() {
return DEVICE_TYPE_SHC.equals(type) || DEVICE_TYPE_SHCA.equals(type);
return DEVICE_SHC.equals(type) || DEVICE_SHCA.equals(type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/
package org.openhab.binding.innogysmarthome.internal.client.entity.message;

import com.google.gson.annotations.SerializedName;

import java.util.List;

import com.google.gson.annotations.SerializedName;

/**
* Defines the structure of a {@link Message}. Messages are part of the innogy system and besides other things are used
* to raise battery warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public void onDeviceStateChanged(final Device device, final Event event) {

logger.trace("DeviceId {} relevant for this handler.", device.getId());

if (event.isLinkedtoDevice() && Device.DEVICE_TYPE_SHCA.equals(device.getType())) {
if (event.isLinkedtoDevice() && DEVICE_SHCA.equals(device.getType())) {
device.getDeviceState().getState().getCpuUsage().setValue(event.getProperties().getCpuUsage());
device.getDeviceState().getState().getDiskUsage().setValue(event.getProperties().getDiskUsage());
device.getDeviceState().getState().getMemoryUsage().setValue(event.getProperties().getMemoryUsage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,16 @@ private boolean initializeProperties() {
}

// Thermostat
if (Device.DEVICE_TYPE_RST.equals(device.getType())
|| Device.DEVICE_TYPE_WRT.equals(device.getType())) {
if (DEVICE_RST.equals(device.getType()) || DEVICE_RST2.equals(device.getType())
|| DEVICE_WRT.equals(device.getType())) {
properties.put(PROPERTY_DISPLAY_CURRENT_TEMPERATURE,
device.getConfig().getDisplayCurrentTemperature());
}

// Meter
if (Device.DEVICE_TYPE_ANALOG_METER.equals(device.getType())
|| Device.DEVICE_TYPE_GENERATION_METER.equals(device.getType())
|| Device.DEVICE_TYPE_SMARTMETER.equals(device.getType())
|| Device.DEVICE_TYPE_TWO_WAY_METER.equals(device.getType())) {
if (DEVICE_ANALOG_METER.equals(device.getType()) || DEVICE_GENERATION_METER.equals(device.getType())
|| DEVICE_SMART_METER.equals(device.getType())
|| DEVICE_TWO_WAY_METER.equals(device.getType())) {
properties.put(PROPERTY_METER_ID, device.getConfig().getMeterId());
properties.put(PROPERTY_METER_FIRMWARE_VERSION, device.getConfig().getMeterFirmwareVersion());
}
Expand Down Expand Up @@ -364,8 +363,7 @@ public void onDeviceStateChanged(final Device device) {
if (reachable != null && !reachable) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Device not reachable.");
return;
} else if ((reachable != null && reachable)
|| Device.DEVICE_TYPE_VARIABLE_ACTUATOR.equals(device.getType())) {
} else if ((reachable != null && reachable) || DEVICE_VARIABLE_ACTUATOR.equals(device.getType())) {
if (device.getDeviceState().deviceIsIncluded()) {
updateStatus(ThingStatus.ONLINE);
} else {
Expand Down

0 comments on commit 8f20990

Please sign in to comment.