]> git.basschouten.com Git - openhab-addons.git/commitdiff
[verisure] Add channel for low battery warning for supported thing types (#10406...
authorJan Gustafsson <jannegpriv@gmail.com>
Wed, 5 May 2021 19:27:53 +0000 (21:27 +0200)
committerGitHub <noreply@github.com>
Wed, 5 May 2021 19:27:53 +0000 (21:27 +0200)
- Add channel for low battery warning for supported thing types

Closes #10406

Signed-off-by: Jan Gustafsson <jannegpriv@gmail.com>
bundles/org.openhab.binding.verisure/README.md
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureBindingConstants.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureBaseThingDTO.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureBatteryStatusDTO.java [new file with mode: 0644]
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureClimatesDTO.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureDoorWindowsDTO.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureClimateDeviceThingHandler.java
bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureDoorWindowThingHandler.java
bundles/org.openhab.binding.verisure/src/main/resources/OH-INF/thing/thing-types.xml

index e0469d94e3e7ba8a012de36563fdb2e991dce423..9f9e83fea571edfd17df1dc21e42fbc1ea3606cb 100644 (file)
@@ -93,13 +93,13 @@ The following channels are supported:
 
 | Channel Type ID     | Item Type | Description                                                                               |
 |---------------------|-----------|-------------------------------------------------------------------------------------------|
-| changedByUser       | String    | This channel reports the user that last changed the state of the alarm.           |
-| changedVia          | String    | This channel reports the method used to change the status.                       |
-| timestamp           | DateTime  | This channel reports the last time the alarm status was changed.                  |
-| installationName    | String    | This channel reports the installation name.                                                |
-| installationId      | Number    | This channel reports the installation ID.                                             |
+| changedByUser       | String    | This channel reports the user that last changed the state of the alarm.                   |
+| changedVia          | String    | This channel reports the method used to change the status.                                |
+| timestamp           | DateTime  | This channel reports the last time the alarm status was changed.                          |
+| installationName    | String    | This channel reports the installation name.                                               |
+| installationId      | Number    | This channel reports the installation ID.                                                 |
 | alarmStatus         | String    | This channel is used to arm/disarm the alarm. Available alarm status are "DISARMED", "ARMED_HOME" and "ARMED_AWAY".|
-| alarmTriggerChannel | trigger   | This is a trigger channel that receives events.|
+| alarmTriggerChannel | trigger   | This is a trigger channel that receives events.                                           |
 
 ### Verisure Yaleman SmartLock
 
@@ -114,11 +114,11 @@ The following channels are supported:
 
 | Channel Type ID         | Item Type | Description                                                                                              |
 |-------------------------|-----------|----------------------------------------------------------------------------------------------------------|
-| changedByUser           | String    | This channel reports the user that last changed the state of the alarm.                             |
+| changedByUser           | String    | This channel reports the user that last changed the state of the alarm.                                  |
 | timestamp               | DateTime  | This channel reports the last time the alarm status was changed.                                         |
-| changedVia              | String    | This channel reports the method used to change the status.                                                 |
-| motorJam                | Switch    | This channel reports if the SmartLock motor has jammed.                                                 |
-| location                | String    | This channel reports the location of the device.                                                                       |
+| changedVia              | String    | This channel reports the method used to change the status.                                               |
+| motorJam                | Switch    | This channel reports if the SmartLock motor has jammed.                                                  |
+| location                | String    | This channel reports the location of the device.                                                         |
 | installationName        | String    | This channel reports the installation name.                                                              |
 | installationId          | Number    | This channel reports the installation ID.                                                                |
 | smartLockStatus         | Switch    | This channel is used to lock/unlock.                                                                     |
@@ -132,7 +132,7 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
@@ -152,7 +152,7 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or on the sensor itself)
 
 #### Channels
 
@@ -161,34 +161,36 @@ The following channels are supported:
 | Channel Type ID             | Item Type             | Description                                                                 |
 |-----------------------------|-----------------------|-----------------------------------------------------------------------------|
 | temperature                 | Number:Temperature    | This channel reports the current temperature.                               |
-| humidity                    | Number                | This channel reports the current humidity in percentage.                   |
+| humidity                    | Number                | This channel reports the current humidity in percentage.                    |
 | humidityEnabled             | Switch                | This channel reports if the Climate is device capable of reporting humidity.|
-| timestamp                   | DateTime              | This channel reports the last time this sensor was updated.                      |
+| timestamp                   | DateTime              | This channel reports the last time this sensor was updated.                 |
 | location                    | String                | This channel reports the location of the device.                            |
 | installationName            | String                | This channel reports the installation name.                                 |
 | installationId              | Number                | This channel reports the installation ID.                                   |
-| smokeDetectorTriggerChannel | trigger               | This is a trigger channel that receives events.|
+| lowBattery                  | Switch                | This channel reports if the battery level is low.                           | 
+| smokeDetectorTriggerChannel | trigger               | This is a trigger channel that receives events.                             |
 
 ### Verisure Water Detector
 
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
 The following channels are supported:
 
 
-| Channel Type ID             | Item Type             | Description                                                  |
-|-----------------------------|-----------------------|--------------------------------------------------------------|
-| temperature                 | Number:Temperature    | This channel reports the current temperature.        |
+
+| Channel Type ID             | Item Type             | Description                                                  | 
+|-----------------------------|-----------------------|--------------------------------------------------------------|                                                                                                                                          
+| temperature                 | Number:Temperature    | This channel reports the current temperature.                |
 | timestamp                   | DateTime              | This channel reports the last time this sensor was updated.  |
-| location                    | String                | This channel reports the location of the device. |
-| installationName            | String                | This channel reports the installation name.      |
-| installationId              | Number                | This channel reports the installation ID.        |
-| waterDetectorTriggerChannel | trigger               | This is a trigger channel that receives events.  |
+| location                    | String                | This channel reports the location of the device.             |
+| installationName            | String                | This channel reports the installation name.                  |
+| installationId              | Number                | This channel reports the installation ID.                    |
+| waterDetectorTriggerChannel | trigger               | This is a trigger channel that receives events.              |
 
 
 ### Verisure Siren
@@ -196,47 +198,48 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
 The following channels are supported:
-
-| Channel Type ID     | Item Type             | Description                                                |
-|---------------------|-----------------------|------------------------------------------------------------|
-| temperature         | Number:Temperature    | This channel reports the current temperature.          |
+| Channel Type ID     | Item Type             | Description                                                | 
+|---------------------|-----------------------|------------------------------------------------------------|                                                                                                                                          
+| temperature         | Number:Temperature    | This channel reports the current temperature.              |
 | timestamp           | DateTime              | This channel reports the last time this sensor was updated.|
-| location            | String                | This channel reports the location.                     |
-| installationName    | String                | This channel reports the installation name.            |
-| installationId      | Number                | This channel reports the installation ID.              |
-| sirenTriggerChannel | trigger               | This is a trigger channel that receives events.        |
+| location            | String                | This channel reports the location.                         |
+| installationName    | String                | This channel reports the installation name.                |
+| installationId      | Number                | This channel reports the installation ID.                  |
+| lowBattery          | Switch                | This channel reports if the battery level is low.          | 
+| sirenTriggerChannel | trigger               | This is a trigger channel that receives events.            |
 
 ### Verisure Night Control
 
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
-The following channels are supported:
-
-| Channel Type ID            | Item Type             | Description                                                |
-|----------------------------|-----------------------|------------------------------------------------------------|
-| temperature                | Number:Temperature    | This channel reports the current temperature.   |
+The following channels are supported: 
+| Channel Type ID            | Item Type             | Description                                                | 
+|----------------------------|-----------------------|------------------------------------------------------------|                                                                                                                                          
+| temperature                | Number:Temperature    | This channel reports the current temperature.              |
 | timestamp                  | DateTime              | This channel reports the last time this sensor was updated.|
-| location                   | String                | This channel reports the location.              |
-| installationName           | String                | This channel reports the installation name.     |
-| installationId             | Number                | This channel reports the installation ID.       |
-| nightControlTriggerChannel | trigger               | This is a trigger channel that receives events. |
+| location                   | String                | This channel reports the location.                         |
+| installationName           | String                | This channel reports the installation name.                |
+| installationId             | Number                | This channel reports the installation ID.                  |
+| lowBattery                 | Switch                | This channel reports if the battery level is low.          | 
+| nightControlTriggerChannel | trigger               | This is a trigger channel that receives events.            |
 
 ### Verisure DoorWindow Sensor
 
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *   Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
@@ -249,7 +252,8 @@ The following channels are supported:
 | location                 | String    | This channel reports the location of the device.                            |
 | installationName         | String    | This channel reports the installation name.                                 |
 | installationId           | Number    | This channel reports the installation ID.                                   |
-| doorWindowTriggerChannel | trigger   | This is a trigger channel that receives events. |
+| lowBattery               | Switch    | This channel reports if the battery level is low.                           | 
+| doorWindowTriggerChannel | trigger   | This is a trigger channel that receives events.                             |
 
 
 ### Verisure User Presence
@@ -257,7 +261,7 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *  Since User presence lacks a Verisure ID, it is constructed from the user's email address, where the '@' sign is removed, and the site id. The following naming convention is used for User presence on site id 123456789 for a user with email address test@gmail.com: 'uptestgmailcom123456789'. Installation ID can be found using DEBUG log settings.
+     *  Since User presence lacks a Verisure ID, it is constructed from the user's email address, where the '@' sign is removed, and the site id. The following naming convention is used for User presence on site id 123456789 for a user with email address test@gmail.com: 'uptestgmailcom123456789'. Installation ID can be found using DEBUG log settings.
 
 #### Channels
 
@@ -278,7 +282,7 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *  Since Broadband connection lacks a Verisure ID, the following naming convention is used for Broadband connection on site id 123456789: 'bc123456789'. Installation ID can be found using DEBUG log settings.
+     *  Since Broadband connection lacks a Verisure ID, the following naming convention is used for Broadband connection on site id 123456789: 'bc123456789'. Installation ID can be found using DEBUG log settings.
 
 #### Channels
 
@@ -296,33 +300,32 @@ The following channels are supported:
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *  Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
+     *  Sensor Id. Example 5A4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the sensor itself)
 
 #### Channels
 
 The following channels are supported:
-
-| Channel Type ID             | Item Type          | Description                                                                         |
-|-----------------------------|--------------------|-------------------------------------------------------------------------------------|
-| countLatestDetection        | Number             | This channel reports the number of mice counts the latest detection during last 24. |
-| countLast24Hours            | Number             | This channel reports the total number of mice counts the last 24h.                 |
+| Channel Type ID             | Item Type          | Description                                                                         | 
+|-----------------------------|--------------------|-------------------------------------------------------------------------------------|                                                                                                                                          
+| countLatestDetection        | Number             | This channel reports the number of mice counts the latest detection during last 24. | 
+| countLast24Hours            | Number             | This channel reports the total number of mice counts the last 24h.                  |
 | durationLatestDetection     | Number:Time        | This channel reports the detection duration in min of latest detection.             |
-| durationLast24Hours         | Number:Time        | This channel reports the total detection duration in min for the last 24 hours.    |
-| timestamp                   | DateTime           | This channel reports time for the last mouse detection.                    |
-| temperature                 | Number:Temperature | This channel reports the current  temperature.                             |
-| temperatureTimestamp        | DateTime           | This channel reports the time for the last temperature reading.                      |
+| durationLast24Hours         | Number:Time        | This channel reports the total detection duration in min for the last 24 hours.     |
+| timestamp                   | DateTime           | This channel reports time for the last mouse detection.                             |
+| temperature                 | Number:Temperature | This channel reports the current  temperature.                                      |
+| temperatureTimestamp        | DateTime           | This channel reports the time for the last temperature reading.                     |
 | location                    | String             | This channel reports the location of the device.                                    |
 | installationName            | String             | This channel reports the installation name.                                         |
 | installationId              | Number             | This channel reports the installation ID.                                           |
-| miceDetectionTriggerChannel | trigger            | This is a trigger channel that receives events. |
+| miceDetectionTriggerChannel | trigger            | This is a trigger channel that receives events.                                     |
 
 ### Verisure Event Log
 
 #### Configuration Options
 
 *   `deviceId` - Device Id
-    *  Since Event Log lacks a Verisure ID, the following naming convention is used for Event Log on site id 123456789: 'el123456789'. Installation ID can be found using DEBUG log settings.
-
+        *  Since Event Log lacks a Verisure ID, the following naming convention is used for Event Log on site id 123456789: 'el123456789'. Installation ID can be found using DEBUG log settings.   
 
 #### Channels
 
@@ -344,7 +347,7 @@ The following channels are supported:
 #### Configuration Options
 
 *    `deviceId` - Device Id
-    *  Sensor Id. Example 3B4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the Gateway itself)
+     *  Sensor Id. Example 3B4C35FT (Note: Verisure ID, found in the Verisure App or My Pages or on the Gateway itself)
 
 #### Channels
 
@@ -368,7 +371,7 @@ The following channels are supported:
 To be able to get trigger events you need an active Event Log thing, you can either get it via auto-detection or create your own in a things-file.
 The following trigger events are defined per thing type:
 
-| Event             | Thing Type    | Description                                                |
+| Event Type        | Thing Type    | Description                                                |
 |-------------------|---------------|------------------------------------------------------------|
 | LOCK              | SmartLock     | SmartLock has been locked.                                 |
 | UNLOCK            | SmartLock     | SmartLock has been locked.                                 |
index 497c4538ca5835faf0d12a77bef3f828a0fdbd6b..c7722d722c89bcb47da004bb7052cfceacf81da5 100644 (file)
@@ -104,6 +104,7 @@ public class VerisureBindingConstants {
     public static final String CHANNEL_NIGHT_CONTROL_TRIGGER_CHANNEL = "nightControlTriggerChannel";
     public static final String CHANNEL_DOOR_WINDOW_TRIGGER_CHANNEL = "doorWindowTriggerChannel";
     public static final String CHANNEL_GATEWAY_TRIGGER_CHANNEL = "gatewayTriggerChannel";
+    public static final String CHANNEL_BATTERY_STATUS = "lowBattery";
 
     // Trigger channel events
     public static final String TRIGGER_EVENT_LOCK = "LOCK";
@@ -162,4 +163,5 @@ public class VerisureBindingConstants {
     public static final String TEMPERATURE_CONTROL_PATH = "/overview/temperaturecontrol";
     public static final String MOUSEDETECTION_PATH = "/overview/mousedetection";
     public static final String CAMERA_PATH = "/overview/camera";
+    public static final String BATTERY_STATUS = "/batterywizard/choose/device?_";
 }
index 45e13592d0b54e0942f4f97d859132e86e88c572..feb094b95aac02724e378190afa532ad8d5fe4e0 100644 (file)
@@ -42,6 +42,7 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.openhab.binding.verisure.internal.dto.VerisureAlarmsDTO;
+import org.openhab.binding.verisure.internal.dto.VerisureBatteryStatusDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureBroadbandConnectionsDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureClimatesDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureDoorWindowsDTO;
@@ -655,6 +656,19 @@ public class VerisureSession {
         }
     }
 
+    private @Nullable VerisureBatteryStatusDTO getBatteryStatus(String deviceId,
+            VerisureBatteryStatusDTO @Nullable [] batteryStatus) {
+        if (batteryStatus != null) {
+            for (VerisureBatteryStatusDTO verisureBatteryStatusDTO : batteryStatus) {
+                String id = verisureBatteryStatusDTO.getId();
+                if (id != null && id.equals(deviceId)) {
+                    return verisureBatteryStatusDTO;
+                }
+            }
+        }
+        return null;
+    }
+
     private synchronized void updateClimateStatus(VerisureInstallation installation) {
         BigDecimal installationId = installation.getInstallationId();
         String url = START_GRAPHQL;
@@ -671,39 +685,53 @@ public class VerisureSession {
             VerisureClimatesDTO thing = postJSONVerisureAPI(url, queryQLClimates, VerisureClimatesDTO.class);
             logger.debug("REST Response ({})", thing);
             List<VerisureClimatesDTO.Climate> climateList = thing.getData().getInstallation().getClimates();
-            climateList.forEach(climate -> {
-                // If thing is Mouse detection device, then skip it, but fetch temperature from it
-                String type = climate.getDevice().getGui().getLabel();
-                if ("MOUSE".equals(type)) {
-                    logger.debug("Mouse detection device!");
+            if (climateList != null) {
+                climateList.forEach(climate -> {
+                    // If thing is Mouse detection device, then skip it, but fetch temperature from it
+                    String type = climate.getDevice().getGui().getLabel();
+                    if ("MOUSE".equals(type)) {
+                        logger.debug("Mouse detection device!");
+                        String deviceId = climate.getDevice().getDeviceLabel();
+                        if (deviceId != null) {
+                            deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId);
+                            VerisureThingDTO mouseThing = verisureThings.get(deviceId);
+                            if (mouseThing != null && mouseThing instanceof VerisureMiceDetectionDTO) {
+                                VerisureMiceDetectionDTO miceDetectorThing = (VerisureMiceDetectionDTO) mouseThing;
+                                miceDetectorThing.setTemperatureValue(climate.getTemperatureValue());
+                                miceDetectorThing.setTemperatureTime(climate.getTemperatureTimestamp());
+                                notifyListeners(miceDetectorThing);
+                                logger.debug("Found climate thing for a Verisure Mouse Detector");
+                            }
+                        }
+                        return;
+                    }
+                    VerisureClimatesDTO cThing = new VerisureClimatesDTO();
+                    VerisureClimatesDTO.Installation inst = new VerisureClimatesDTO.Installation();
+                    inst.setClimates(Collections.singletonList(climate));
+                    VerisureClimatesDTO.Data data = new VerisureClimatesDTO.Data();
+                    data.setInstallation(inst);
+                    cThing.setData(data);
+                    // Set unique deviceID
                     String deviceId = climate.getDevice().getDeviceLabel();
                     if (deviceId != null) {
-                        deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId);
-                        VerisureThingDTO mouseThing = verisureThings.get(deviceId);
-                        if (mouseThing != null && mouseThing instanceof VerisureMiceDetectionDTO) {
-                            VerisureMiceDetectionDTO miceDetectorThing = (VerisureMiceDetectionDTO) mouseThing;
-                            miceDetectorThing.setTemperatureValue(climate.getTemperatureValue());
-                            miceDetectorThing.setTemperatureTime(climate.getTemperatureTimestamp());
-                            notifyListeners(miceDetectorThing);
-                            logger.debug("Found climate thing for a Verisure Mouse Detector");
+                        try {
+                            VerisureBatteryStatusDTO[] batteryStatusThingArray = getJSONVerisureAPI(BATTERY_STATUS,
+                                    VerisureBatteryStatusDTO[].class);
+                            VerisureBatteryStatusDTO batteryStatus = getBatteryStatus(deviceId,
+                                    batteryStatusThingArray);
+                            if (batteryStatus != null) {
+                                logger.debug("REST Response ({})", batteryStatus);
+                                cThing.setBatteryStatus(batteryStatus);
+                            }
+                        } catch (ExecutionException | InterruptedException | TimeoutException | JsonSyntaxException e) {
+                            logger.warn("Failed to query for smartlock status: {}", e.getMessage());
                         }
+                        // Set location
+                        cThing.setLocation(climate.getDevice().getArea());
+                        notifyListenersIfChanged(cThing, installation, deviceId);
                     }
-                    return;
-                }
-                VerisureClimatesDTO cThing = new VerisureClimatesDTO();
-                VerisureClimatesDTO.Installation inst = new VerisureClimatesDTO.Installation();
-                inst.setClimates(Collections.singletonList(climate));
-                VerisureClimatesDTO.Data data = new VerisureClimatesDTO.Data();
-                data.setInstallation(inst);
-                cThing.setData(data);
-                // Set unique deviceID
-                String deviceId = climate.getDevice().getDeviceLabel();
-                if (deviceId != null) {
-                    // Set location
-                    cThing.setLocation(climate.getDevice().getArea());
-                    notifyListenersIfChanged(cThing, installation, deviceId);
-                }
-            });
+                });
+            }
         } catch (ExecutionException | InterruptedException | TimeoutException | JsonSyntaxException
                 | PostToAPIException e) {
             logger.warn("Failed to send a POST to the API {}", e.getMessage());
@@ -736,6 +764,17 @@ public class VerisureSession {
                 // Set unique deviceID
                 String deviceId = doorWindow.getDevice().getDeviceLabel();
                 if (deviceId != null) {
+                    try {
+                        VerisureBatteryStatusDTO[] batteryStatusThingArray = getJSONVerisureAPI(BATTERY_STATUS,
+                                VerisureBatteryStatusDTO[].class);
+                        VerisureBatteryStatusDTO batteryStatus = getBatteryStatus(deviceId, batteryStatusThingArray);
+                        if (batteryStatus != null) {
+                            logger.debug("REST Response ({})", batteryStatus);
+                            dThing.setBatteryStatus(batteryStatus);
+                        }
+                    } catch (ExecutionException | InterruptedException | TimeoutException | JsonSyntaxException e) {
+                        logger.warn("Failed to query for smartlock status: {}", e.getMessage());
+                    }
                     // Set location
                     dThing.setLocation(doorWindow.getDevice().getArea());
                     notifyListenersIfChanged(dThing, installation, deviceId);
index 08e3ea6e30ffdca81e344ab0d00a942bea8b070d..39b63731c21d7bd7b3333800f24e9be5255bb8a5 100644 (file)
@@ -264,7 +264,7 @@ public abstract class VerisureBaseThingDTO implements VerisureThingDTO {
             return broadband;
         }
 
-        public List<Climate> getClimates() {
+        public @Nullable List<Climate> getClimates() {
             return climates;
         }
 
diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureBatteryStatusDTO.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/dto/VerisureBatteryStatusDTO.java
new file mode 100644 (file)
index 0000000..1c8847f
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2010-2021 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.verisure.internal.dto;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * The battery status of the Verisure System.
+ *
+ * @author Jan Gustafsson - Initial contribution
+ *
+ */
+@NonNullByDefault
+public class VerisureBatteryStatusDTO {
+
+    public boolean chosen;
+    public @Nullable String id;
+    public @Nullable String pictureBase;
+    public @Nullable String translatedType;
+    public @Nullable String location;
+    public @Nullable String batteryInfo;
+    public @Nullable String status;
+    public @Nullable String alias;
+    public int index;
+    public boolean selectable;
+
+    public @Nullable String getId() {
+        return id;
+    }
+
+    public @Nullable String getLocation() {
+        return location;
+    }
+
+    public @Nullable String getBatteryInfo() {
+        return batteryInfo;
+    }
+
+    public @Nullable String getStatus() {
+        return status;
+    }
+}
index e2a7aabe7d1381de4d11613071bcf1d9f95d57ea..c9f2804afd26920350d20b7a6f87bdbd8a8d12ef 100644 (file)
@@ -29,6 +29,16 @@ import com.google.gson.annotations.SerializedName;
 @NonNullByDefault
 public class VerisureClimatesDTO extends VerisureBaseThingDTO {
 
+    private @Nullable VerisureBatteryStatusDTO batteryStatus;
+
+    public @Nullable VerisureBatteryStatusDTO getBatteryStatus() {
+        return batteryStatus;
+    }
+
+    public void setBatteryStatus(@Nullable VerisureBatteryStatusDTO batteryStatus) {
+        this.batteryStatus = batteryStatus;
+    }
+
     @Override
     public ThingTypeUID getThingTypeUID() {
         String type = getData().getInstallation().getClimates().get(0).getDevice().getGui().getLabel();
@@ -64,6 +74,15 @@ public class VerisureClimatesDTO extends VerisureBaseThingDTO {
         if (getClass() != obj.getClass()) {
             return false;
         }
+        VerisureClimatesDTO other = (VerisureClimatesDTO) obj;
+        VerisureBatteryStatusDTO localBatteryStatusJSON = batteryStatus;
+        if (localBatteryStatusJSON == null) {
+            if (other.batteryStatus != null) {
+                return false;
+            }
+        } else if (!localBatteryStatusJSON.equals(other.batteryStatus)) {
+            return false;
+        }
         return true;
     }
 
index f5b3860bf6f1b13cf95b73013d05281fcb8ba3cb..37161dbabf6dfc65ce55966bd8f6eef8ab528edf 100644 (file)
@@ -29,6 +29,16 @@ import com.google.gson.annotations.SerializedName;
 @NonNullByDefault
 public class VerisureDoorWindowsDTO extends VerisureBaseThingDTO {
 
+    private @Nullable VerisureBatteryStatusDTO batteryStatus;
+
+    public @Nullable VerisureBatteryStatusDTO getBatteryStatus() {
+        return batteryStatus;
+    }
+
+    public void setBatteryStatus(@Nullable VerisureBatteryStatusDTO batteryStatus) {
+        this.batteryStatus = batteryStatus;
+    }
+
     @Override
     public ThingTypeUID getThingTypeUID() {
         return THING_TYPE_DOORWINDOW;
@@ -53,6 +63,15 @@ public class VerisureDoorWindowsDTO extends VerisureBaseThingDTO {
         if (getClass() != obj.getClass()) {
             return false;
         }
+        VerisureDoorWindowsDTO other = (VerisureDoorWindowsDTO) obj;
+        VerisureBatteryStatusDTO localBatteryStatusJSON = batteryStatus;
+        if (localBatteryStatusJSON == null) {
+            if (other.batteryStatus != null) {
+                return false;
+            }
+        } else if (!localBatteryStatusJSON.equals(other.batteryStatus)) {
+            return false;
+        }
         return true;
     }
 
index 237176ec850e036ff959e830fe3be0504d0827b1..1ac6f65852875841b2914f86f5a039257e7bf26a 100644 (file)
@@ -21,6 +21,7 @@ import javax.measure.quantity.Dimensionless;
 import javax.measure.quantity.Temperature;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.verisure.internal.dto.VerisureBatteryStatusDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureClimatesDTO;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.QuantityType;
@@ -97,6 +98,15 @@ public class VerisureClimateDeviceThingHandler extends VerisureThingHandler<Veri
             case CHANNEL_LOCATION:
                 String location = climateJSON.getLocation();
                 return location != null ? new StringType(location) : UnDefType.NULL;
+            case CHANNEL_BATTERY_STATUS:
+                VerisureBatteryStatusDTO batteryStatus = climateJSON.getBatteryStatus();
+                if (batteryStatus != null) {
+                    String status = batteryStatus.getStatus();
+                    if (status != null && status.equals("CRITICAL")) {
+                        return OnOffType.from(true);
+                    }
+                }
+                return OnOffType.from(false);
         }
         return UnDefType.UNDEF;
     }
index 389c1f4352f0b1850d630772d8e98dc4dc5435d9..d44d2ff70af591bdb368910f5d675bf1885b02b1 100644 (file)
@@ -19,8 +19,10 @@ import java.util.List;
 import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.verisure.internal.dto.VerisureBatteryStatusDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureDoorWindowsDTO;
 import org.openhab.binding.verisure.internal.dto.VerisureDoorWindowsDTO.DoorWindow;
+import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.thing.Channel;
@@ -64,7 +66,7 @@ public class VerisureDoorWindowThingHandler extends VerisureThingHandler<Verisur
             getThing().getChannels().stream().map(Channel::getUID)
                     .filter(channelUID -> isLinked(channelUID) && !channelUID.getId().equals("timestamp"))
                     .forEach(channelUID -> {
-                        State state = getValue(channelUID.getId(), doorWindow);
+                        State state = getValue(channelUID.getId(), doorWindow, doorWindowJSON);
                         updateState(channelUID, state);
 
                     });
@@ -75,13 +77,22 @@ public class VerisureDoorWindowThingHandler extends VerisureThingHandler<Verisur
         }
     }
 
-    public State getValue(String channelId, DoorWindow doorWindow) {
+    public State getValue(String channelId, DoorWindow doorWindow, VerisureDoorWindowsDTO doorWindowJSON) {
         switch (channelId) {
             case CHANNEL_STATE:
                 return "OPEN".equals(doorWindow.getState()) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
             case CHANNEL_LOCATION:
                 String location = doorWindow.getDevice().getArea();
                 return location != null ? new StringType(location) : UnDefType.UNDEF;
+            case CHANNEL_BATTERY_STATUS:
+                VerisureBatteryStatusDTO batteryStatus = doorWindowJSON.getBatteryStatus();
+                if (batteryStatus != null) {
+                    String status = batteryStatus.getStatus();
+                    if (status != null && status.equals("CRITICAL")) {
+                        return OnOffType.from(true);
+                    }
+                }
+                return OnOffType.from(false);
         }
         return UnDefType.UNDEF;
     }
index 44223628ecedb0bea64e2ae9dadae911103beb63..975586957d26ccf67ef8e930700bf8c3c2a8d6c6 100644 (file)
                        <channel id="installationName" typeId="installationName"/>
                        <channel id="installationId" typeId="installationId"/>
                        <channel id="smokeDetectorTriggerChannel" typeId="triggerChannel"/>
+                       <channel id="lowBattery" typeId="system.low-battery"/>
                </channels>
 
                <properties>
                        <channel id="installationName" typeId="installationName"/>
                        <channel id="installationId" typeId="installationId"/>
                        <channel id="sirenTriggerChannel" typeId="triggerChannel"/>
+                       <channel id="lowBattery" typeId="system.low-battery"/>
                </channels>
 
                <properties>
                        <channel id="installationName" typeId="installationName"/>
                        <channel id="installationId" typeId="installationId"/>
                        <channel id="nightControlTriggerChannel" typeId="triggerChannel"/>
+                       <channel id="lowBattery" typeId="system.low-battery"/>
                </channels>
 
                <properties>
                        <channel id="installationName" typeId="installationName"/>
                        <channel id="installationId" typeId="installationId"/>
                        <channel id="doorWindowTriggerChannel" typeId="triggerChannel"/>
+                       <channel id="lowBattery" typeId="system.low-battery"/>
                </channels>
 
                <properties>