]> _ Git - tortuga-home.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Apr 2024 07:00:00 +0000 (09:00 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Apr 2024 07:00:00 +0000 (09:00 +0200)
.idea/workspace.xml
scripts/lib/homeassistant.php
scripts/lib/homeconnect.php [deleted file]
scripts/lib/scenes.php

index 9bfd5915e7f90d0fa5a5a02c08944b512ce83b51..3bdac88cbc96bf37e43590ebac0266d54b7d203f 100644 (file)
@@ -6,6 +6,8 @@
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/homeassistant.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/homeassistant.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/homeconnect.php" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
       <workItem from="1713261983472" duration="644000" />
       <workItem from="1713376517416" duration="792000" />
       <workItem from="1713440657070" duration="147000" />
-      <workItem from="1713531985684" duration="129000" />
+      <workItem from="1713531985684" duration="2444000" />
+      <workItem from="1713941353441" duration="532000" />
     </task>
     <task id="LOCAL-00502" summary=".">
       <created>1641726946298</created>
       <option name="project" value="LOCAL" />
       <updated>1687259667913</updated>
     </task>
-    <option name="localTasksCounter" value="613" />
+    <option name="localTasksCounter" value="614" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
index 79ce5c651e110e4968821d45043355b1bf01e665..83c79c869c2ac49e8a49452c785f3920075557e6 100644 (file)
@@ -17,6 +17,8 @@ const HA_OFFICE_SCREEN='cover.office_screen';
 const HA_OFFICE_MAIN_SCREEN = 'switch.0xa4c138787633f01d';
 const HA_OFFICE_PLANE_SCREENS = 'switch.0xa4c138ba535d2cc5';
 
+const HA_COFFEE='switch.machine_a_cafe_power';
+
 const HA_SALON_PROJ_SENSOR='binary_sensor.0x00158d00094363cc_contact';
 
 function haGetState($id, $attribute = null) { //ID to read - for example sensor.foo
diff --git a/scripts/lib/homeconnect.php b/scripts/lib/homeconnect.php
deleted file mode 100644 (file)
index f4b50f1..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-function _hc_cmd($cmd, $data = [], $method = 'get', $auth = true)
-{
-    $client = getHttpClient(false);
-    $base = 'https://api.home-connect.com';
-    $uri = $base . '/' . $cmd;
-    $headers = [];
-    if ($auth) {
-        $headers['Authorization'] = 'Bearer ' . getState('hc_access_token');
-        $headers['Accept'] = 'application/vnd.bsh.sdk.v1+json';
-    }
-    try {
-        $res = httpRequest($uri, $method, $data, null, 10, true, $headers);
-    } catch (Exception $e) {
-        if (stristr($e->getMessage(), 'token')) {
-            hc_connect(true);
-            return _hc_cmd($cmd, $data, $method, $auth);
-        }else{
-            echo $e->getMessage();
-        }
-    }
-    $c = $res->getBody()->getContents();
-
-    if ($decoded = json_decode($c)) {
-        return $decoded;
-    } else {
-        return $c;
-    }
-}
-
-
-function hc_appliances()
-{
-    hc_connect();
-    $cacheId = 'hc_appliances';
-    $res = getStateIfMoreRecent($cacheId, time() - (86400 * 7), null);
-    if (null === $res) {
-        $res = [];
-        $appliances = _hc_cmd('api/homeappliances')->data->homeappliances;
-        foreach ($appliances as $item) {
-            $res[$item->name] = ['haid' => $item->haId, 'type' => $item->type];
-        }
-        setState($cacheId, $res);
-    }
-    return $res;
-}
-
-function hc_haid($name)
-{
-    $appliances = hc_appliances();
-    return $appliances[$name]['haid'];
-}
-
-function hc_type($name)
-{
-    $appliances = hc_appliances();
-    return $appliances[$name]['type'];
-}
-
-function hc_command($appliance, $cmd)
-{
-    $haid = hc_haid($appliance);
-}
-
-
-function hc_setpower_state($appliance, $state)
-{
-    $data = [];
-    $aptype = hc_type($appliance);
-    $stby = ['Oven', 'CoffeeMaker'];
-    if (in_array($aptype, $stby)) {
-        $states = ['On', 'Standby'];
-    } else {
-        $states = ['On', 'Off'];
-    }
-    $value = $state ? $states[0] : $states[1];
-    $data = ['key' => 'BSH.Common.Setting.PowerState',
-        'value' => 'BSH.Common.EnumType.PowerState.' . $value,
-        'type' => 'BSH.Common.EnumType.PowerState',
-        'contraints' => ['allowedvalues' => ['BSH.Common.EnumType.Powerstate.' . $states[0], 'BSH.Common.EnumType.Powerstate.' . $states[1]]]];
-
-    return _hc_cmd("api/homeappliances/" . hc_haid($appliance) . "/settings/BSH.Common.Setting.PowerState", ['data' => $data], 'put');
-}
-
-function coffee_on()
-{
-    hc_setpower_state('Machine à café', true);
-}
-
-function coffee_off()
-{
-    hc_setpower_state('Machine à café', false);
-}
-
-function hc_connect($refresh = false)
-{
-    $scope = 'IdentifyAppliance Monitor Settings';
-    $appName = 'Tortuga';
-    $locale = 'fr';
-
-    if ($refresh || null === getStateIfMoreRecent('hc_access_token', null, time() - 86400)) {
-        // Init connection
-        $connect = _hc_cmd('security/oauth/device_authorization', [
-            'client_id' => HOMECONNECT_CLIENT_ID,
-            'scope' => $scope,
-        ], 'post', false);
-        print_r($connect);
-
-        // Login
-        $login = _hc_cmd('security/oauth/device_login', [
-            'client_id' => HOMECONNECT_CLIENT_ID,
-            'user_code' => $connect->user_code,
-            'email' => HOMECONNECT_USERNAME,
-            'password' => HOMECONNECT_PASSWORD,
-        ], 'post', false);
-        preg_match('/<input type="hidden" name="session_id" value="([-a-z0-9]*)"\/>/', $login, $matches);
-        $session_id = $matches[1];
-
-        // Grant
-        $grant = _hc_cmd('security/oauth/device_grant',
-            [
-                'client_id' => HOMECONNECT_CLIENT_ID,
-                'app_name' => $appName,
-                'session_id' => $session_id,
-                'user_code' => $connect->user_code,
-                'input_aborted' => 'false',
-                'accept_language' => $locale,
-                'email' => HOMECONNECT_USERNAME,
-                "region" => "EU", "environment" => "PRD",
-                'scope' => $scope
-            ], 'post', false);
-
-        // Token request
-        $token = _hc_cmd('security/oauth/token',
-            [
-                'grant_type' => 'device_code',
-                'device_code' => $connect->device_code,
-                'client_id' => HOMECONNECT_CLIENT_ID,
-            ], 'post', false);
-    } else if (getState('hc_access_token_expires' < time())) {
-        $token = _hc_cmd('security/oauth/token',
-            [
-                'grant_type' => 'refresh_token',
-                'refresh_token' => getState('hc_refresh_token'),
-                'client_id' => HOMECONNECT_CLIENT_ID,
-            ], 'post', false);
-    } else {
-        return;
-    }
-
-    setState('hc_access_token', $token->access_token);
-    setState('hc_refresh_token', $token->refresh_token);
-}
\ No newline at end of file
index 06233cae1c715a7723023dfec883381cc8e0034c..52e3cb2154e5ebbf647645fdbe7ea7f1e4337bc8 100644 (file)
@@ -657,8 +657,6 @@ $scenes = [
         ['type' => 'scene', 'scene' => 'chambre/off'],
         ['type' => 'scene', 'scene' => 'sdb/off'],
         ['type' => 'scene', 'scene' => 'wc/off'],
-        ['type' => 'function', 'function' => 'stopHarmony'],
-        ['type' => 'function', 'function' => 'stopAllSqueezebox'],
         ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/on'],
         ['type' => 'scene', 'scene' => 'chambre/planetarium/off'],
         ['type' => 'scene', 'scene' => 'cuisine/coffee/off'],
@@ -667,6 +665,8 @@ $scenes = [
         ['type' => 'scene', 'scene' => 'salon/media/off'],
         ['type' => 'scene', 'scene' => 'salon/off', 'delay' => 2],
         ['type' => 'scene', 'scene' => 'sdb/hotwater/auto'],
+        ['type' => 'function', 'function' => 'stopHarmony'],
+        ['type' => 'function', 'function' => 'stopAllSqueezebox'],
     ],
 
     'home/welcome/eco' => [
@@ -826,10 +826,10 @@ $scenes = [
         //['type' => 'hue', 'group' => $cuisine, 'scene' => array('on' => false)]
     ],
     'cuisine/coffee/on' => [
-        ['type' => 'function', 'function' => 'coffee_on'],
+        ['type' => 'ha', 'device' => HA_COFFEE],
     ],
     'cuisine/coffee/off' => [
-        ['type' => 'function', 'function' => 'coffee_off'],
+        ['type' => 'ha', 'device' => HA_COFFEE, 'command' => 'turn_off'],
     ],
     'cour/auto' => [
         ['type' => 'function', 'function' => 'courAuto', 'args' => [true]],