2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nikohomecontrol.internal.protocol.nhc2;
15 import java.util.concurrent.ScheduledExecutorService;
16 import java.util.concurrent.ScheduledFuture;
17 import java.util.concurrent.TimeUnit;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.nikohomecontrol.internal.protocol.NhcEnergyMeter;
22 import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication;
25 * The {@link NhcEnergyMeter} class represents the energyMeters metering Niko Home Control communication object. It
26 * contains all fields representing a Niko Home Control energyMeters meter and has methods to receive energyMeters usage
29 * @author Mark Herwege - Initial Contribution
32 public class NhcEnergyMeter2 extends NhcEnergyMeter {
34 private ScheduledExecutorService scheduler;
35 private volatile @Nullable ScheduledFuture<?> restartTimer;
38 private String technology;
40 protected NhcEnergyMeter2(String id, String name, String model, String technology,
41 NikoHomeControlCommunication nhcComm, ScheduledExecutorService scheduler) {
42 super(id, name, nhcComm);
44 this.technology = technology;
46 this.scheduler = scheduler;
50 * Start the flow from energy information from the energy meter. The Niko Home Control energy meter will send power
51 * information every 2s for 30s. This method will retrigger every 25s to make sure the information continues
52 * flowing. If the information is no longer required, make sure to use the {@link stopEnergyMeter} method to stop
53 * the flow of information.
55 * @param topic topic the start event will have to be sent to every 25s
56 * @param gsonMessage content of message
58 public void startEnergyMeter(String topic, String gsonMessage) {
60 restartTimer = scheduler.scheduleWithFixedDelay(() -> {
61 ((NikoHomeControlCommunication2) nhcComm).executeEnergyMeter(topic, gsonMessage);
62 }, 0, 25, TimeUnit.SECONDS);
66 * Cancel receiving energy information from the controller. We therefore stop the automatic retriggering of the
67 * subscription, see {@link startEnergyMeter}.
69 public void stopEnergyMeter() {
70 ScheduledFuture<?> timer = restartTimer;
78 * @return model as returned from Niko Home Control
80 public String getModel() {
85 * @return technology as returned from Niko Home Control
87 public String getTechnology() {