From 45cf7592a96c74e54cfff53671ae10219ecf019e Mon Sep 17 00:00:00 2001 From: Mark Herwege <mherwege@users.noreply.github.com> Date: Tue, 7 Apr 2020 00:32:31 +0200 Subject: [PATCH] [nikohomecontrol] Removed dead code (#7314) * [nikohomecontrol] Small README updates. * Remove obsolete profiles list as these cannot be retrieved with hobby API. * Fix timezone property. * Removed acting on public messages as not available in hobby API. Signed-off-by: Mark Herwege <mark.herwege@telenet.be> --- .../NikoHomeControlBridgeHandler2.java | 10 ++--- .../internal/protocol/nhc2/NhcMessage2.java | 2 - .../internal/protocol/nhc2/NhcProfile2.java | 38 ------------------ .../internal/protocol/nhc2/NhcTimeInfo2.java | 6 +-- .../nhc2/NikoHomeControlCommunication2.java | 39 +------------------ 5 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcProfile2.java diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java index b6cdcfadba7cd..2997c00423819 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java @@ -142,9 +142,9 @@ protected void updateProperties() { if (!waterTariff.isEmpty()) { properties.put("waterTariff", waterTariff); } - String timeZone = comm.getTimeInfo().getTimeZone(); - if (!timeZone.isEmpty()) { - properties.put("timeZone", timeZone); + String timezone = comm.getTimeInfo().getTimezone(); + if (!timezone.isEmpty()) { + properties.put("timezone", timezone); } String isDst = comm.getTimeInfo().getIsDst(); if (!isDst.isEmpty()) { @@ -154,10 +154,6 @@ protected void updateProperties() { if (!services.isEmpty()) { properties.put("services", services); } - String profiles = comm.getProfiles(); - if (!profiles.isEmpty()) { - properties.put("profiles", profiles); - } thing.setProperties(properties); } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcMessage2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcMessage2.java index f6000d543474b..26eb1c4bd226a 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcMessage2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcMessage2.java @@ -29,8 +29,6 @@ static class NhcMessageParam { @Nullable List<NhcSystemInfo2> systemInfo; @Nullable - List<NhcProfile2> profiles; - @Nullable List<NhcService2> services; @Nullable List<NhcDevice2> devices; diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcProfile2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcProfile2.java deleted file mode 100644 index 15dbf7b5122a8..0000000000000 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcProfile2.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.nikohomecontrol.internal.protocol.nhc2; - -/** - * {@link NhcProfile2} represents a Niko Home Control II profile. It is used when parsing the profile response json. - * - * @author Mark Herwege - Initial Contribution - * - */ -class NhcProfile2 { - - String name; - String type; - String uuid; - - String name() { - return name; - } - - String uuid() { - return uuid; - } - - String profile() { - return "(" + name + ": " + uuid + ")"; - } -} diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcTimeInfo2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcTimeInfo2.java index a4940fed5caec..3567b06a5f0a0 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcTimeInfo2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcTimeInfo2.java @@ -25,7 +25,7 @@ public class NhcTimeInfo2 { @SerializedName(value = "GMTOffset") String gmtOffset = ""; - String timeZone = ""; + String timezone = ""; String isDST = ""; @SerializedName(value = "UTCTime") String utcTime = ""; @@ -40,8 +40,8 @@ public String getGMTOffset() { /** * @return the timeZone */ - public String getTimeZone() { - return timeZone; + public String getTimezone() { + return timezone; } /** diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java index d8ee9065f2732..70eec24f20b3d 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java @@ -71,7 +71,6 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication private final NhcMqttConnection2 mqttConnection; - private final List<NhcProfile2> profiles = new CopyOnWriteArrayList<>(); private final List<NhcService2> services = new CopyOnWriteArrayList<>(); private volatile String profile = ""; @@ -168,9 +167,6 @@ private void initialize() throws MqttException { message.method = "systeminfo.publish"; mqttConnection.connectionPublish(profile + "/system/cmd", gson.toJson(message)); - message.method = "profiles.list"; - mqttConnection.connectionPublish("public/authentication/cmd", gson.toJson(message)); - message.method = "services.list"; mqttConnection.connectionPublish(profile + "/authentication/cmd", gson.toJson(message)); @@ -233,27 +229,6 @@ private void systeminfoPublishRsp(String response) { } } - private void profilesListRsp(String response) { - Type messageType = new TypeToken<NhcMessage2>() { - }.getType(); - List<NhcProfile2> profileList = null; - try { - NhcMessage2 message = gson.fromJson(response, messageType); - List<NhcMessageParam> messageParams = message.params; - if (messageParams != null) { - profileList = messageParams.stream().filter(p -> (p.profiles != null)).findFirst().get().profiles; - } - } catch (JsonSyntaxException e) { - logger.debug("Niko Home Control: unexpected json {}", response); - } catch (NoSuchElementException ignore) { - // Ignore if profiles not present in response, this should not happen in a profiles response - } - profiles.clear(); - if (profileList != null) { - profiles.addAll(profileList); - } - } - private void servicesListRsp(String response) { Type messageType = new TypeToken<NhcMessage2>() { }.getType(); @@ -791,14 +766,11 @@ private void sendDeviceMessage(String topic, String gsonMessage) { @Override public void processMessage(String topic, byte[] payload) { String message = new String(payload); - if ("public/system/evt".equals(topic) || (profile + "/system/evt").equals(topic)) { + if ((profile + "/system/evt").equals(topic)) { systemEvt(message); } else if ((profile + "/system/rsp").equals(topic)) { logger.debug("Niko Home Control: received topic {}, payload {}", topic, message); systeminfoPublishRsp(message); - } else if ("public/authentication/rsp".equals(topic)) { - logger.debug("Niko Home Control: received topic {}, payload {}", topic, message); - profilesListRsp(message); } else if ((profile + "/notification/evt").equals(topic)) { logger.debug("Niko Home Control: received topic {}, payload {}", topic, message); notificationEvt(message); @@ -811,7 +783,7 @@ public void processMessage(String topic, byte[] payload) { } else if ((profile + "/authentication/rsp").equals(topic)) { logger.debug("Niko Home Control: received topic {}, payload {}", topic, message); servicesListRsp(message); - } else if ("public/control/devices.error".equals(topic) || (profile + "/control/devices.error").equals(topic)) { + } else if ((profile + "/control/devices.error").equals(topic)) { logger.warn("Niko Home Control: received error {}", message); } else { logger.trace("Niko Home Control: not acted on received message topic {}, payload {}", topic, message); @@ -840,13 +812,6 @@ public NhcTimeInfo2 getTimeInfo() { return timeInfo; } - /** - * @return comma separated list of profiles with uuid's retrieved from Connected Controller - */ - public String getProfiles() { - return profiles.stream().map(NhcProfile2::profile).collect(Collectors.joining(", ")); - } - /** * @return comma separated list of services retrieved from Connected Controller */