* Adding a request counter channel to Api Bridge thing.
Signed-off-by: clinique <gael@lhopital.org>
(*) Strictly said this parameter is not mandatory at first run, until you grant your binding on Netatmo Connect. Once present, you'll not have to grant again.
+**Supported channels for the Account bridge thing:**
+
+| Channel Group | Channel Id | Item Type | Description |
+|---------------|---------------|-----------|-------------------------------------------------------------------|
+| monitoring | request-count | Number | Number of request transmitted to Netatmo API during the last hour |
+
+
### Configure the Bridge
1. Complete the Netatmo Application Registration if you have not already done so, see above.
public static final String GROUP_PROPERTIES = "properties";
public static final String GROUP_SETPOINT = "setpoint";
public static final String GROUP_LOCATION = "location";
+ public static final String GROUP_MONITORING = "monitoring";
// Alternative extended groups
public static final String OPTION_EXTENDED = "-extended";
public static final String CHANNEL_HOME_EVENT = "home-event";
public static final String CHANNEL_SETPOINT_DURATION = "setpoint-duration";
public static final String CHANNEL_FLOODLIGHT = "floodlight";
+ public static final String CHANNEL_REQUEST_COUNT = "request-count";
}
import org.openhab.binding.netatmo.internal.handler.capability.SmokeCapability;
import org.openhab.binding.netatmo.internal.handler.capability.WeatherCapability;
import org.openhab.binding.netatmo.internal.handler.channelhelper.AirQualityChannelHelper;
+import org.openhab.binding.netatmo.internal.handler.channelhelper.ApiBridgeChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.CameraChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EnergyChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EventChannelHelper;
@NonNullByDefault
public enum ModuleType {
UNKNOWN(FeatureArea.NONE, "", null, Set.of()),
- ACCOUNT(FeatureArea.NONE, "", null, Set.of()),
+ ACCOUNT(FeatureArea.NONE, "", null, Set.of(), new ChannelGroup(ApiBridgeChannelHelper.class, GROUP_MONITORING)),
HOME(FeatureArea.NONE, "NAHome", ACCOUNT,
Set.of(DeviceCapability.class, HomeCapability.class, ChannelHelperCapability.class),
*/
package org.openhab.binding.netatmo.internal.handler;
+import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.util.ArrayDeque;
import java.util.Collection;
+import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.openhab.binding.netatmo.internal.servlet.GrantServlet;
import org.openhab.binding.netatmo.internal.servlet.WebhookServlet;
import org.openhab.core.config.core.Configuration;
+import org.openhab.core.library.types.DecimalType;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
private Map<Class<? extends RestManager>, RestManager> managers = new HashMap<>();
private @Nullable WebhookServlet webHookServlet;
private @Nullable GrantServlet grantServlet;
+ private Deque<LocalDateTime> requestsTimestamps;
+ private final ChannelUID requestCountChannelUID;
public ApiBridgeHandler(Bridge bridge, HttpClient httpClient, NADeserializer deserializer,
BindingConfiguration configuration, HttpService httpService) {
this.httpClient = httpClient;
this.deserializer = deserializer;
this.httpService = httpService;
+ this.requestsTimestamps = new ArrayDeque<>(200);
+ this.requestCountChannelUID = new ChannelUID(getThing().getUID(), GROUP_MONITORING, CHANNEL_REQUEST_COUNT);
}
@Override
updateStatus(ThingStatus.UNKNOWN);
GrantServlet servlet = new GrantServlet(this, httpService);
servlet.startListening();
- this.grantServlet = servlet;
+ grantServlet = servlet;
scheduler.execute(() -> openConnection(null, null));
}
}
}
+ if (isLinked(requestCountChannelUID)) {
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime oneHourAgo = now.minusHours(1);
+ requestsTimestamps.addLast(now);
+ while (requestsTimestamps.getFirst().isBefore(oneHourAgo)) {
+ requestsTimestamps.removeFirst();
+ }
+ updateState(requestCountChannelUID, new DecimalType(requestsTimestamps.size()));
+ }
ContentResponse response = request.send();
Code statusCode = HttpStatus.getCode(response.getStatus());
--- /dev/null
+/**
+ * Copyright (c) 2010-2022 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.netatmo.internal.handler.channelhelper;
+
+import java.util.Set;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * The {@link ApiBridgeChannelHelper} handle specifics channels the Netatmo Bridge
+ *
+ * @author Gaël L'hopital - Initial contribution
+ *
+ */
+@NonNullByDefault
+public class ApiBridgeChannelHelper extends ChannelHelper {
+
+ public ApiBridgeChannelHelper(Set<String> providedGroups) {
+ super(providedGroups);
+ }
+}
binding.config.netatmo.readFriends.description = For Weather Stations: A friend gave you access to their Netatmo Weather Station.
# channel group types
-
+channel-group-type.netatmo.monitoring.label = API Monitoring
channel-group-type.netatmo.airquality-extended.label = Air Quality
channel-group-type.netatmo.airquality.label = Air Quality
channel-group-type.netatmo.battery-extended.label = Battery
channel-group-type.netatmo.wind.channel.max-strength-date.description = Moment when max wind strength was recorded.
# channel types
-
+channel-type.netatmo.request-count.label = Request Count
+channel-type.netatmo.request-count.description = Number of request transmitted to Netatmo API during the last hour.
channel-type.netatmo.absolute-pressure.label = Absolute Pressure
channel-type.netatmo.absolute-pressure.description = Pressure measured relative to a full vacuum.
channel-type.netatmo.alim-status.label = Alim State
<state readOnly="false" pattern="%s"/>
</channel-type>
+ <channel-type id="request-count" advanced="true">
+ <item-type>Number</item-type>
+ <label>Request Count</label>
+ <description>Number of request transmitted to Netatmo API during the last hour.</description>
+ <state readOnly="true" pattern="%d"/>
+ </channel-type>
+
<channel-type id="person-count">
<item-type>Number</item-type>
<label>Person Count</label>
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
+ <channel-group-type id="monitoring">
+ <label>API Monitoring</label>
+ <channels>
+ <channel id="request-count" typeId="request-count"/>
+ </channels>
+ </channel-group-type>
+
<channel-group-type id="signal">
<label>Signal</label>
<channels>