]> git.basschouten.com Git - openhab-addons.git/commitdiff
[unifi] Fixed 404 error with reconnect and no default value set for UniFiOS Checkbox...
authorMathias Maes <watcherwhale@maes.family>
Sat, 31 Jul 2021 16:55:34 +0000 (18:55 +0200)
committerGitHub <noreply@github.com>
Sat, 31 Jul 2021 16:55:34 +0000 (18:55 +0200)
* Fixed 404 error by obtaining Csrf token before login

Signed-off-by: Mathias Maes <watcherwhale@maes.family>
* Only try to obtain a csrf token when using UniFi OS

Signed-off-by: Mathias Maes <watcherwhale@maes.family>
* Updated documentation

Signed-off-by: Mathias Maes <watcherwhale@maes.family>
* Updated thing configuration in README.md

Signed-off-by: Mathias Maes <watcherwhale@maes.family>
bundles/org.openhab.binding.unifi/README.md
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/model/UniFiController.java
bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml

index 6fdd0a2436b1a0b9dcc8cd52b56e6f93953a0d99..48bfa135e2576afefa61d537b0e4020c939ae47a 100644 (file)
@@ -29,6 +29,7 @@ The following table describes the Bridge configuration parameters:
 | ------------------------ | ---------------------------------------------- |--------- | ------- |
 | host                     | Hostname of IP address of the UniFi Controller | Required | -       |
 | port                     | Port of the UniFi Controller                   | Required | -       |
+| unifios                  | If the UniFi Controller is running on UniFi OS | Required | false   |
 | username                 | The username to access the UniFi Controller    | Required | -       |
 | password                 | The password to access the UniFi Controller    | Required | -       |
 | refresh                  | Refresh interval in seconds                    | Optional | 10      |
@@ -106,7 +107,7 @@ The `reconnect` channel allows you to force a client to reconnect. Sending `ON`
 things/unifi.things
 
 ```
-Bridge unifi:controller:home "UniFi Controller" [ host="unifi", port=8443, username="$username", password="$password", refresh=10 ] {
+Bridge unifi:controller:home "UniFi Controller" [ host="unifi", port=8443, unifios=false, username="$username", password="$password", refresh=10 ] {
        Thing wirelessClient matthewsPhone "Matthew's iPhone" [ cid="$cid", site="default", considerHome=180 ]
 }
 ```
index 6dbdc35c869262c488bbf4db20897f2ee5981b4e..639a07f7fd2af8e48bace0a94ac95a5c50b89d51 100644 (file)
@@ -94,6 +94,10 @@ public class UniFiController {
     // Public API
 
     public void start() throws UniFiException {
+        if (unifios) {
+            obtainCsrfToken();
+        }
+
         login();
     }
 
@@ -101,9 +105,15 @@ public class UniFiController {
         logout();
     }
 
-    public void login() throws UniFiException {
+    public void obtainCsrfToken() throws UniFiException {
         csrfToken = "";
 
+        UniFiControllerRequest<Void> req = newRequest(Void.class);
+        req.setPath("/");
+        executeRequest(req);
+    }
+
+    public void login() throws UniFiException {
         UniFiControllerRequest<Void> req = newRequest(Void.class);
         req.setPath(unifios ? "/api/auth/login" : "/api/login");
         req.setBodyParameter("username", username);
index 7632c4b5a1c27116a43ac3867b368016dc2959b8..87069a33ca094968b173f5159544596a069d8112 100644 (file)
@@ -24,6 +24,7 @@
                        <parameter name="unifios" type="boolean" required="true">
                                <label>UniFi OS</label>
                                <description>If the UniFi Controller is running on UniFi OS.</description>
+                               <default>false</default>
                        </parameter>
                        <parameter name="username" type="text" required="true">
                                <label>Username</label>