From: Vincent Date: Mon, 19 Apr 2021 19:39:33 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b269093f9b7c7a06533ce7bab4b624b487323657;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 72cb789..6cb04e6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,22 @@ + + - + + + + + + + + + + + + + + - - @@ -280,6 +293,17 @@ diff --git a/config/global.php b/config/global.php index efc0ae0..66312e7 100644 --- a/config/global.php +++ b/config/global.php @@ -10,6 +10,11 @@ define("SQUEEZEBOX_SPOTIFY_PASSWORD", '?Z8}#HK+SZrQ'); define('HUE_BRIDGE', '192.168.13.85'); define('HUE_USER', 'zZigF7nPQq9nTZ3GTB1zkntn98trOJVFHWAwFiqQ'); +define('HOMECONNECT_CLIENT_ID','97C087A66769555561D14306F34336C5D05AD97B56ED813E6BD44ECCFA980CE5'); +define('HOMECONNECT_CLIENT_SECRET','540F102E39E86F7F92C3A534C31017264A47458589E9E66D27427F35DD4F7BFC'); +define('HOMECONNECT_USERNAME','vincent@enhydra.fr'); +define('HOMECONNECT_PASSWORD','YcR%vNmYnu%e$3dx2idM'); + define('LATITUDE', 48.8758392); define('LONGITUDE', 2.3422104); diff --git a/config/salon.php b/config/salon.php index 2661511..b339380 100644 --- a/config/salon.php +++ b/config/salon.php @@ -7,7 +7,7 @@ config('TVPLAYER', 'shield'); config('VOLUME_DEVICE', 'DenonAVR'); config('VIDEOPLAYER_DEVICE', 'salon'); config('HIDEMASK_TIMEOUT', 250); -config('THEME','#7a6854'); +config('THEME','#d0a25b'); config('SLEEPSCREEN', 15); config('SCREENSAVER_BRIGHTNESS', 100); config('SLEEPTYPE', 'screensaver'); diff --git a/images/rooms/medium/cuisine.jpg b/images/rooms/medium/cuisine.jpg index 7895241..b78ca7e 100644 Binary files a/images/rooms/medium/cuisine.jpg and b/images/rooms/medium/cuisine.jpg differ diff --git a/images/rooms/medium/salon.jpg b/images/rooms/medium/salon.jpg index fe0c1a4..5d92fc5 100644 Binary files a/images/rooms/medium/salon.jpg and b/images/rooms/medium/salon.jpg differ diff --git a/images/rooms/originaux/cuisine.jpg b/images/rooms/originaux/cuisine.jpg index 8ddf21e..b78ca7e 100644 Binary files a/images/rooms/originaux/cuisine.jpg and b/images/rooms/originaux/cuisine.jpg differ diff --git a/images/rooms/originaux/salon.jpg b/images/rooms/originaux/salon.jpg index 1e8b28c..5d92fc5 100644 Binary files a/images/rooms/originaux/salon.jpg and b/images/rooms/originaux/salon.jpg differ diff --git a/images/rooms/small/cuisine.jpg b/images/rooms/small/cuisine.jpg index fdd2242..b78ca7e 100644 Binary files a/images/rooms/small/cuisine.jpg and b/images/rooms/small/cuisine.jpg differ diff --git a/images/rooms/small/salon.jpg b/images/rooms/small/salon.jpg index 4fe3d2a..5d92fc5 100644 Binary files a/images/rooms/small/salon.jpg and b/images/rooms/small/salon.jpg differ diff --git a/scripts/homeconnect.php b/scripts/homeconnect.php new file mode 100644 index 0000000..50363f8 --- /dev/null +++ b/scripts/homeconnect.php @@ -0,0 +1,4 @@ +'; +hc_setpower_state('Machine à café',false); \ No newline at end of file diff --git a/scripts/lib/homeconnect.php b/scripts/lib/homeconnect.php new file mode 100644 index 0000000..94e88e9 --- /dev/null +++ b/scripts/lib/homeconnect.php @@ -0,0 +1,142 @@ +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() +{ + $scope = 'IdentifyAppliance Monitor Settings'; + $appName = 'Tortuga'; + $locale = 'fr'; + + if (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/http.php b/scripts/lib/http.php index cd99e87..6db1664 100644 --- a/scripts/lib/http.php +++ b/scripts/lib/http.php @@ -48,7 +48,11 @@ function httpRequest($url, $method = 'get', $data = [], $auth = null, $timeout = } if ($method == 'GET') { $options['query'] = $data; + } + if ($method === 'PUT') { + $options['json']=$data; } else { + if (is_string($data)) { $options['body'] = $data; } else { diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 4f1865a..0fd8a87 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -47,6 +47,7 @@ require_once ROOT . '/scripts/lib/proc.php'; require_once ROOT . '/scripts/lib/shield.php'; require_once ROOT . '/scripts/lib/kodi.php'; require_once ROOT . '/scripts/lib/climacell.php'; +require_once ROOT . '/scripts/lib/homeconnect.php'; profile('Loaded libraries', __FILE__, __LINE__); diff --git a/scripts/lib/redis.php b/scripts/lib/redis.php index 76cf99a..e85ad30 100644 --- a/scripts/lib/redis.php +++ b/scripts/lib/redis.php @@ -2,6 +2,8 @@ use Predis\Client; + + class StringSetIb extends Predis\Command\StringSet { diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index b17bb42..0377826 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -34,7 +34,7 @@ $scenes = [ ['type' => 'scene', 'scene' => 'chambre/planetarium/off'], ['type' => 'function', 'function' => 'bedbrightness', 'args' => [255]], ['type' => 'phonetask', 'phone' => 'vincent', 'task' => 'Matin'], - ['type' => 'ifttt', 'event' => 'coffee_on'], + ['type' => 'function', 'function' => 'coffee_on'], ['type' => 'scene', 'scene' => 'chambre/auto', 'delay' => 35], ], 'chambre/deshumidificateur/on' => [ @@ -631,11 +631,10 @@ $scenes = [ ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/on'], ['type' => 'phonetask', 'phone' => 'vincent', 'task' => 'Stop All Sounds'], ['type' => 'scene', 'scene' => 'chambre/planetarium/off'], - ['type' => 'ifttt', 'event' => 'coffee_off'], + ['type' => 'function', 'function' => 'coffee_off'], ['type' => 'scene', 'scene' => 'home/hueoff'], ['type' => 'scene', 'scene' => 'salon/media/off'], ['type' => 'scene', 'scene' => 'salon/off', 'delay' => 2], - //['type' => 'ifttt', 'event' => 'oven_off'], ], 'home/welcome' => [ ['type' => 'scene', 'scene' => 'cuisine/on'], diff --git a/scripts/lib/state.php b/scripts/lib/state.php index f5f73b0..af2d5ba 100644 --- a/scripts/lib/state.php +++ b/scripts/lib/state.php @@ -1,12 +1,16 @@ igbset('state_' . $key, $value); + if (!$expires) { + connectRedis()->igbset('state_' . $key, $value); + } else { + connectRedis()->igbsetex('state_' . $key, $value, $expires); + } } function getState($key, $default = null) @@ -21,6 +25,6 @@ function getState($key, $default = null) function getStateIfMoreRecent($key, $time, $default = null) { $redis = connectRedis(); - $redis->expireAt($key, $time); + //$redis->expireAt($key, $time); return getState($key, $default); } \ No newline at end of file