<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">
+++ /dev/null
-<?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
['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'],
['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' => [
//['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]],