]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tado] Add channel for PresenceState and support setting HOME/AWAY. Fixes #8826 ...
authorStefan Profanter <Pro@users.noreply.github.com>
Thu, 29 Oct 2020 16:58:49 +0000 (17:58 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Oct 2020 16:58:49 +0000 (17:58 +0100)
Signed-off-by: Stefan Profanter <pro@users.noreply.github.com>
bundles/org.openhab.binding.tado/README.md
bundles/org.openhab.binding.tado/pom.xml
bundles/org.openhab.binding.tado/src/main/api/pom.xml
bundles/org.openhab.binding.tado/src/main/api/tado-api.yaml
bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java
bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java
bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java
bundles/org.openhab.binding.tado/src/main/resources/OH-INF/thing/thing-types.xml

index 5cc7a1a10277dcf39448dbdf52f7be72fd47b099..69c03afdac7c84def4e9f53e9b90acccdd5906ef 100644 (file)
@@ -3,7 +3,7 @@
 The tado° binding integrates devices from [tado°](https://www.tado.com).
 
 It requires a fully functional tado° installation.
-You can then monitor and control all zone types (Heating, AC, Hot Water) as well as retrieve the HOME/AWAY status of mobile devices.
+You can then monitor and control all zone types (Heating, AC, Hot Water) as well as retrieve the HOME/AWAY status of mobile devices, and setting the HOME/AWAY status of your home.
 
 ## `home` Thing (the Bridge)
 
@@ -24,6 +24,12 @@ Bridge tado:home:demo [ username="mail@example.com", password="secret" ]
 
 Afterwards the discovery will show all zones and mobile devices associated with the user's home.
 
+### Channels
+
+Name | Type | Description | Read/Write
+-|-|-|-|-
+`homePresence` | String | Current presence value of the tado home. `HOME` and `AWAY` can be set | RW
+
 ## `zone` Thing
 
 A *zone* is an area/room of your home.
@@ -143,6 +149,7 @@ Bridge tado:home:demo [ username="mail@example.com", password="secret" ] {
 ## tado.items
 
 ```
+Switch             TADO_PRESENCE_home             "Tado Presence: [MAP(presence.map):%s]"               { channel="tado:home:demo:homePresence" }
 Number:Temperature HEAT_inside_temperature    "Inside Temperature"      { channel="tado:zone:demo:heating:currentTemperature" }
 Number             HEAT_humidity              "Humidity"                { channel="tado:zone:demo:heating:humidity" }
 Number             HEAT_heating_power         "Heating Power"           { channel="tado:zone:demo:heating:heatingPower" }
@@ -179,6 +186,10 @@ Switch             Phone_atHome               "Phone location [MAP(presence.map)
 ```
 sitemap tado label="Tado"
 {
+    Frame label="Status" {
+        Switch item=TADO_PRESENCE_home  icon="presence"
+    }
+
     Frame label="Heating" {
         Text      item=HEAT_inside_temperature
         Text      item=HEAT_humidity
index dc875d448f022664448fb82a6714947198062447..820647def0bf3207952032ee099c535a70b043dd 100644 (file)
@@ -18,7 +18,7 @@
     <dependency>
       <groupId>org.openhab.binding.tado</groupId>
       <artifactId>api-client</artifactId>
-      <version>1.3.0</version>
+      <version>1.4.1</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>
index 6269fb3ab76423d879310fff6e630957e127a84b..db567d4d0538834c986dccafde94abb0b95f9f48 100644 (file)
@@ -5,7 +5,7 @@
 
        <groupId>org.openhab.binding.tado</groupId>
        <artifactId>api-client</artifactId>
-       <version>1.3.0</version>
+       <version>1.4.1</version>
 
        <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
index 363ab0ca90c7f3e5a508e11c0c1f8d3e90dad831..53d21c9579dabaa0958b3b1932c1ebf2e3fd9075 100644 (file)
@@ -73,6 +73,62 @@ paths:
         404:
           $ref: "#/responses/NotFound"
 
+  /homes/{home_id}/state:
+    get:
+      operationId: homeState
+      summary: Get state of home
+      tags:
+      - home
+      security:
+      - oauth:
+        - home.details:read
+      description: This will the current presence state of the home (HOME/AWAY).
+      parameters:
+      - $ref: "#/parameters/homeID"
+      responses:
+        200:
+          description: Home State
+          schema:
+            $ref: "#/definitions/HomeState"
+        401:
+          $ref: "#/responses/Unauthorized"
+        403:
+          $ref: "#/responses/AccessDenied"
+        404:
+          $ref: "#/responses/NotFound"
+
+  /homes/{home_id}/presenceLock:
+    put:
+      operationId: updatePresenceLock
+      summary: Set a presence lock state, i.e., HOME or AWAY
+      tags:
+        - home
+      security:
+        - oauth:
+            - home.operation:write
+      description: This will set the presence mode of the home
+      parameters:
+        - $ref: "#/parameters/homeID"
+        - name: json
+          in: body
+          description: The new presence settings.
+          required: true
+          schema:
+            $ref: "#/definitions/HomePresence"
+      responses:
+        200:
+          description: Presence mode successfully updated.
+        400:
+          $ref: "#/responses/BadRequest"
+        401:
+          $ref: "#/responses/Unauthorized"
+        403:
+          $ref: "#/responses/AccessDenied"
+        404:
+          $ref: "#/responses/NotFound"
+        422:
+          $ref: "#/responses/UnprocessableEntity"
+
   /homes/{home_id}/zones:
     get:
       operationId: listZones
@@ -368,6 +424,37 @@ definitions:
     - temperatureUnit
     - awayRadiusInMeters
 
+  HomeState:
+    type: object
+    properties:
+      presence:
+        description: Presence State.
+        $ref: "#/definitions/PresenceState"
+      name:
+        description: User defined name for the home.
+        type: string
+        readOnly: true
+      presenceLocked:
+        description: Not sure what this does..
+        type: boolean
+        readOnly: true
+      showHomePresenceSwitchButton:
+        description: Not sure what this does..
+        type: boolean
+        readOnly: true
+    required:
+      - presence
+      - presenceLocked
+
+  HomePresence:
+    type: object
+    properties:
+      homePresence:
+        description: Presence State.
+        $ref: "#/definitions/PresenceState"
+    required:
+      - homePresence
+
   TadoSystemType:
     description: The system type of the zone.
     type: string
@@ -426,6 +513,13 @@ definitions:
     - 'ON'
     - 'OFF'
 
+  PresenceState:
+    type: string
+    description: Enum to represent presence state.
+    enum:
+    - 'HOME'
+    - 'AWAY'
+
   GenericZoneSetting:
     type: object
     discriminator: type
index 3a2cc09e25cf64c8ffe8676aeee858133ad4a223..a8d2a312ee9b7294fdb3915552172c8fcb98d6bd 100644 (file)
@@ -41,6 +41,8 @@ public class TadoBindingConstants {
         FAHRENHEIT
     }
 
+    public static final String CHANNEL_HOME_PRESENCE_MODE = "homePresence";
+
     public static final String CHANNEL_ZONE_CURRENT_TEMPERATURE = "currentTemperature";
     public static final String CHANNEL_ZONE_HUMIDITY = "humidity";
 
index 523211210e3936fb40d0d69b01ca98a135c3c183..555d762caa8010324425d6a09a7e472f71bf6fa4 100644 (file)
@@ -22,14 +22,19 @@ import org.openhab.binding.tado.internal.api.ApiException;
 import org.openhab.binding.tado.internal.api.HomeApiFactory;
 import org.openhab.binding.tado.internal.api.client.HomeApi;
 import org.openhab.binding.tado.internal.api.model.HomeInfo;
+import org.openhab.binding.tado.internal.api.model.HomePresence;
+import org.openhab.binding.tado.internal.api.model.HomeState;
+import org.openhab.binding.tado.internal.api.model.PresenceState;
 import org.openhab.binding.tado.internal.api.model.User;
 import org.openhab.binding.tado.internal.config.TadoHomeConfig;
+import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingStatusDetail;
 import org.openhab.core.thing.binding.BaseBridgeHandler;
 import org.openhab.core.types.Command;
+import org.openhab.core.types.RefreshType;
 import org.openhab.core.types.State;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -126,9 +131,44 @@ public class TadoHomeHandler extends BaseBridgeHandler {
         return homeId;
     }
 
+    public HomeState getHomeState() throws IOException, ApiException {
+        HomeApi api = getApi();
+        return api != null ? api.homeState(getHomeId()) : null;
+    }
+
+    public void updateHomeState() {
+        try {
+            updateState(TadoBindingConstants.CHANNEL_HOME_PRESENCE_MODE,
+                    getHomeState().getPresence() == PresenceState.HOME ? OnOffType.ON : OnOffType.OFF);
+        } catch (IOException | ApiException e) {
+            logger.debug("Error accessing tado server: {}", e.getMessage(), e);
+        }
+    }
+
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
-        // Nothing to do for a bridge
+        String id = channelUID.getId();
+
+        if (command == RefreshType.REFRESH) {
+            updateHomeState();
+            return;
+        }
+
+        switch (id) {
+            case TadoBindingConstants.CHANNEL_HOME_PRESENCE_MODE:
+                HomePresence presence = new HomePresence();
+                presence.setHomePresence(command.toFullString().toUpperCase().equals("ON")
+                        || command.toFullString().toUpperCase().equals("HOME") ? PresenceState.HOME
+                                : PresenceState.AWAY);
+                try {
+                    api.updatePresenceLock(homeId, presence);
+                } catch (IOException | ApiException e) {
+                    logger.warn("Error setting home presence: {}", e.getMessage(), e);
+                }
+
+                break;
+
+        }
     }
 
     public State getBatteryLowAlarm(long zoneId) {
index 3b01e366e616f8e36fff91bb34b90a1333fd908d..7abd80f27f93991c2705dfbd7c02d70909a60735 100644 (file)
@@ -218,6 +218,11 @@ public class TadoZoneHandler extends BaseHomeThingHandler {
     }
 
     private void updateZoneState(boolean forceUpdate) {
+        TadoHomeHandler home = getHomeHandler();
+        if (home != null) {
+            home.updateHomeState();
+        }
+
         // No update during HVAC change debounce
         if (!forceUpdate && scheduledHvacChange != null && !scheduledHvacChange.isDone()) {
             return;
@@ -258,7 +263,6 @@ public class TadoZoneHandler extends BaseHomeThingHandler {
                     "Could not connect to server due to " + e.getMessage());
         }
 
-        TadoHomeHandler home = getHomeHandler();
         if (home != null) {
             updateState(TadoBindingConstants.CHANNEL_ZONE_BATTERY_LOW_ALARM, home.getBatteryLowAlarm(getZoneId()));
         }
index 90c6da3120ff0a39e258bfd5db531880058524d0..2b213c992c008887298915184a73b35140c22169 100644 (file)
@@ -9,6 +9,10 @@
                <label>Tado Home</label>
                <description>The user's tado home</description>
 
+               <channels>
+                       <channel typeId="homePresence" id="homePresence"></channel>
+               </channels>
+
                <config-description>
                        <parameter name="username" type="text" required="true">
                                <label>User Name</label>
                </config-description>
        </thing-type>
 
+       <channel-type id="homePresence">
+               <item-type>Switch</item-type>
+               <label>At Home</label>
+               <description>ON if at home, OFF if away</description>
+       </channel-type>
+
        <channel-type id="currentTemperature">
                <item-type>Number:Temperature</item-type>
                <label>Temperature</label>