From: Vincent Date: Wed, 21 Apr 2021 07:17:43 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ce78c463139732529cc42c13039bce726afaa16c;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 31199d3..984e413 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,11 @@ - + + + + diff --git a/scripts/homeconnect.php b/scripts/homeconnect.php index 50363f8..4522c55 100644 --- a/scripts/homeconnect.php +++ b/scripts/homeconnect.php @@ -1,4 +1,4 @@ '; -hc_setpower_state('Machine à café',false); \ No newline at end of file +hc_setpower_state('Machine à café',true); \ No newline at end of file diff --git a/scripts/lib/homeconnect.php b/scripts/lib/homeconnect.php index 94e88e9..543a650 100644 --- a/scripts/lib/homeconnect.php +++ b/scripts/lib/homeconnect.php @@ -9,7 +9,14 @@ function _hc_cmd($cmd, $data = [], $method = 'get', $auth = true) $headers['Authorization'] = 'Bearer ' . getState('hc_access_token'); $headers['Accept'] = 'application/vnd.bsh.sdk.v1+json'; } - $res = httpRequest($uri, $method, $data, null, 10, true, $headers); + try { + $res = httpRequest($uri, $method, $data, null, 10, true, $headers); + } catch (Exception $e) { + if (stristr($e->getMessage(), 'The access token expired')) { + hc_connect(true); + return _hc_cmd($cmd, $data, $method, $auth); + } + } $c = $res->getBody()->getContents(); if ($decoded = json_decode($c)) { @@ -70,24 +77,26 @@ function hc_setpower_state($appliance, $state) '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'); + 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_on() +{ + hc_setpower_state('Machine à café', true); } -function coffee_off(){ - hc_setpower_state('Machine à café',false); +function coffee_off() +{ + hc_setpower_state('Machine à café', false); } -function hc_connect() +function hc_connect($refresh = false) { $scope = 'IdentifyAppliance Monitor Settings'; $appName = 'Tortuga'; $locale = 'fr'; - if (null === getStateIfMoreRecent('hc_access_token', null, time() - 86400)) { + if ($refresh || null === getStateIfMoreRecent('hc_access_token', null, time() - 86400)) { // Init connection $connect = _hc_cmd('security/oauth/device_authorization', [ 'client_id' => HOMECONNECT_CLIENT_ID, diff --git a/scripts/lib/remoteinfos.php b/scripts/lib/remoteinfos.php index c20f619..ac39839 100644 --- a/scripts/lib/remoteinfos.php +++ b/scripts/lib/remoteinfos.php @@ -20,7 +20,16 @@ function remoteInfos() if (config('TVPLAYER') === 'shield') { if (shieldGetCurrentApp() === 'kodi') { $res = ['type' => 'shieldmedia', 'can_seek' => true]; - $p = json_decode(httpRequest('http://' . getDevice()['shield'] . ':8754/jsonrpc?Base=1', 'post', '[{"jsonrpc":"2.0","method":"Player.GetProperties","params":[1,["playlistid","speed","position","totaltime","time","percentage","shuffled","repeat","canrepeat","canshuffle","canseek","partymode"]],"id":1},{"jsonrpc":"2.0","method":"Player.GetItem","params":[1,["title","thumbnail","file","artist","genre","year","rating","album","track","duration","playcount","dateadded","episode","artistid","albumid","tvshowid","fanart"]],"id":2}]', ['kodi', 'atacama'], 10, true, ['X-Requested-With' => 'XMLHttpRequest', 'Content-type' => 'application/json'])->getBody(), true); + while (true) { + try { + $req = httpRequest('http://' . getDevice()['shield'] . ':8754/jsonrpc?Base=1', 'post', '[{"jsonrpc":"2.0","method":"Player.GetProperties","params":[1,["playlistid","speed","position","totaltime","time","percentage","shuffled","repeat","canrepeat","canshuffle","canseek","partymode"]],"id":1},{"jsonrpc":"2.0","method":"Player.GetItem","params":[1,["title","thumbnail","file","artist","genre","year","rating","album","track","duration","playcount","dateadded","episode","artistid","albumid","tvshowid","fanart"]],"id":2}]', ['kodi', 'atacama'], 10, true, ['X-Requested-With' => 'XMLHttpRequest', 'Content-type' => 'application/json']); + break; + } catch (Exception $e) { + + } + sleep(2); + } + $p = json_decode($req->getBody(), true); $res['duration'] = ''; $res['time'] = ''; $res['title'] = ''; diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 142e790..8591f0d 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -252,7 +252,7 @@ $scenes = [ ['type' => 'domoticz', 'scene' => 43, 'command' => true, 'priority' => true], ], 'chambre/cheminee/smallfire' => [ - ['type' => 'domoticz', 'scene' => 43, 'command' => true, 'priority' => true], + ['type' => 'domoticz', 'scene' => 44, 'command' => true, 'priority' => true], ], 'chambre/cheminee/cold' => [ ['type' => 'domoticz', 'scene' => 43, 'command' => true, 'priority' => true], diff --git a/servers/domoticz.php b/servers/domoticz.php index 0c635fa..65b2b65 100644 --- a/servers/domoticz.php +++ b/servers/domoticz.php @@ -34,6 +34,6 @@ function handleDomoticzQueue() $redis->igbset($q, $queue); echo 'Run command ' . json_encode($command) . "\n"; runDomoticzCommand($command); - usleep(1000000 * 0.5); + usleep(1000000 * 0.25); } } \ No newline at end of file