From 35d118e4690e36a5078b686e0b4228d34c292b2c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 24 Apr 2024 09:00:00 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 7 +- scripts/lib/homeassistant.php | 2 + scripts/lib/homeconnect.php | 153 ---------------------------------- scripts/lib/scenes.php | 8 +- 4 files changed, 11 insertions(+), 159 deletions(-) delete mode 100644 scripts/lib/homeconnect.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9bfd591..3bdac88 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,8 @@ + + diff --git a/scripts/lib/homeassistant.php b/scripts/lib/homeassistant.php index 79ce5c6..83c79c8 100644 --- a/scripts/lib/homeassistant.php +++ b/scripts/lib/homeassistant.php @@ -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 index f4b50f1..0000000 --- a/scripts/lib/homeconnect.php +++ /dev/null @@ -1,153 +0,0 @@ -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('//', $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 diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 06233ca..52e3cb2 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -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]], -- 2.39.5