From 91d82f97b68dded6b85189e0db16dfebc34c7d07 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sun, 9 Jul 2023 18:36:53 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 5 +-- scripts/homeassistant_device_event.php | 60 ++++++++++++++++++++------ 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5794efd..387394e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,7 +6,6 @@ - diff --git a/scripts/homeassistant_device_event.php b/scripts/homeassistant_device_event.php index de10350..b026bf0 100644 --- a/scripts/homeassistant_device_event.php +++ b/scripts/homeassistant_device_event.php @@ -5,38 +5,44 @@ $_GET['im'] = '5'; if ($_GET['state'] === 'None') { exit; } -$wcswitch = 'sensor.0x0c4314fffe7ce957_action'; -$cubebureau = 'sensor.0x00158d00042d7082_action'; -$switchBedroom = 'binary_sensor.switch_bedroom'; -$cubeSDB = 'sensor.0x00158d0005c19a86_action'; -$cubeSalon1 = 'sensor.0x00158d00029ba2b6_action'; -$cubeSalon2 = 'sensor.0x00158d00042dc656_action'; -$cubeSalon3 = 'sensor.0x00158d00058a55da_action'; +const HA_WC_SWITCH = 'sensor.0x0c4314fffe7ce957_action'; +const HA_CUBE_BUREAU = 'sensor.0x00158d00042d7082_action'; +const HA_CUBE_BUREAU_SIDE = 'sensor.0x00158d00042d7082_side'; +const HA_SWITCH_BEDROOM = 'binary_sensor.switch_bedroom'; +const HA_CUBE_BATHROOM = 'sensor.0x00158d0005c19a86_action'; +const HA_CUBE_SALON_1 = 'sensor.0x00158d00029ba2b6_action'; +const HA_CUBE_SALON_2 = 'sensor.0x00158d00042dc656_action'; +const HA_CUBE_SALON_3 = 'sensor.0x00158d00058a55da_action'; switch ($_GET['id']) { - case $wcswitch: + case HA_WC_SWITCH: $action = 'wcSwitch'; $forceConfig = 'wc'; break; - case $cubebureau: + case HA_CUBE_BUREAU: $forceConfig = 'bureau'; $action = 'cubeBureau'; break; - case $switchBedroom: + case HA_CUBE_BUREAU_SIDE: + $forceConfig = 'bureau'; + $action = 'setCubeFace'; + break; + case HA_SWITCH_BEDROOM: $forceConfig = 'chambre'; $action = 'chambreToggle'; break; - case $cubeSDB: + case HA_CUBE_BATHROOM: $forceConfig = 'sdb'; $action = 'cubeSDB'; break; - case $cubeSalon1: - case $cubeSalon2: - case $cubeSalon3: + case HA_CUBE_SALON_1: + case HA_CUBE_SALON_2: + case HA_CUBE_SALON_3: $forceConfig = 'salon'; $action = 'cubeSalon'; break; + default: exit; } @@ -45,6 +51,19 @@ require_once "import.php"; $action(); + +function setCubeFace() { + setState('cube_face_' . $_GET['id'], $_GET['state']); +} + +function getCubeFace($id = null) { + if (null === $id) { + $id = $_GET['id']; + } + $id = str_replace('_action', '_side', $id); + return (int)getState('cube_face_' . $id, 1); +} + function wcSwitch() { switch ($_GET['state']) { case '1_double': @@ -75,6 +94,7 @@ function cubeBureau() { die('0'); } + $face = getCubeFace(); // Cube bureau switch ($_GET['state']) { case 'shake': @@ -91,6 +111,10 @@ function cubeBureau() { off('bureau'); break; case 'slide': + if ($face == 5) { + haAction('script.klarstein_fan_toggle'); + break; + } if (getCurrentHarmonyActivity() === HARMONY_TV) { _remoteCmd('pause', 'bureau'); } else { @@ -99,9 +123,17 @@ function cubeBureau() { } break; case 'rotate_right': + if ($face == 5) { + haAction('script.klarstein_fan_speed_up'); + break; + } volume(config('VOLUME_STEP'), '+'); break; case 'rotate_left': + if ($face == 5) { + haAction('script.klarstein_fan_speed_down'); + break; + } volume(config('VOLUME_STEP'), '-'); break; case 'tap': -- 2.39.5