From 8e6789c1b63ac9dbd86556925438fdf1b272675a Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 6 Feb 2021 20:34:20 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 35 +++++++++++++------- config/global.php | 3 +- config/salon.php | 2 +- scripts/denon.php | 8 ++++- scripts/domoticz_device_event.php | 8 ++--- scripts/lib/denon.php | 54 +++++++++++++++++++++++++++++++ scripts/lib/domoticz.php | 18 +++++++++-- scripts/lib/lib.php | 3 ++ scripts/lib/off.php | 2 ++ scripts/lib/proc.php | 15 ++++++--- scripts/lib/shield.php | 3 +- scripts/shield.php | 2 ++ servers/logcat.php | 8 +++-- 13 files changed, 133 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5bd1505..c011974 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,18 @@ - - + + + + + + + + + + + + diff --git a/config/global.php b/config/global.php index 596750a..b39776c 100644 --- a/config/global.php +++ b/config/global.php @@ -17,7 +17,8 @@ $squeezeboxPlayers = array( 'Salle de bains' => 'b8:27:eb:ab:b4:50', //'Salon' => 'dc:a6:32:02:47:c1', //'Salon' => 'cc:cc:2d:15:82:0e', - 'Salon' => '5a:a1:4c:5c:e7:5e', + //'Salon' => '5a:a1:4c:5c:e7:5e', + 'Salon' => 'bb:bb:78:49:8f:a4s', 'Chambre' => 'b8:27:eb:31:e1:44', //'WC' => '00:04:20:2a:05:2e', //'WC' => 'b8:27:eb:78:f6:88', diff --git a/config/salon.php b/config/salon.php index 96cbdc9..a24d718 100644 --- a/config/salon.php +++ b/config/salon.php @@ -4,7 +4,7 @@ config('ROOM', 'salon'); config('SQUEEZEBOX_PLAYER', 'Salon'); config('VIDEOPLAYER', 'shield'); config('TVPLAYER', 'shield'); -config('VOLUME_DEVICE', 'harmony'); +config('VOLUME_DEVICE', 'DenonAVR'); config('VIDEOPLAYER_DEVICE', 'salon'); config('HIDEMASK_TIMEOUT', 250); config('THEME','#7a6854'); diff --git a/scripts/denon.php b/scripts/denon.php index 13cb661..4cc5667 100644 --- a/scripts/denon.php +++ b/scripts/denon.php @@ -1,3 +1,9 @@ ['method' => 'GET'], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]]; + $context = stream_context_create($context); + return file_get_contents('https://192.168.13.42:10443/ajax/globals/' . $command . '&_' . time(), false, $context); +} + +function denonAVRVolume($volume, $increase = '') +{ + $device = 2894; + $current = domoticzGetLevel($device); + if ($increase === '+' || $increase === '-') { + if ($increase === '+') { + $volume += $current; + } else { + $volume = $current - $volume; + } + } + $volume = min(80, $volume); + domoticzSetLevel($device, $volume, true); + return $current . '->' . $volume; +} + +function denonAVROn($input = 'Media Player') +{ + _denonAVR('set_config?type=4&data=' . rawurlencode('1')); + denonAVRInput($input); +} + +function denonAVRInput($input) +{ + $map = ['Media Player' => 5, 'CD' => 9, 'HEOS Music' => 13]; + $volumes = ['Media Player' => 40, 'HEOS Music' => 50, 'CD' => 30]; + if (isset($map[$input])) { + _denonAVR('set_config?type=7&data=' . rawurlencode('')); + sleep(1); + } + if (isset($volumes[$input])) { + denonAVRVolume($volumes[$input]); + sleep(1); + } +} + +function denonAVROff() +{ + _denonAVR('set_config?type=4&data=' . rawurlencode('3')); +} + +function epson($on = true) +{ + $cmd = $on ? 'PowerOn' : 'PowerOff'; + sshCommand('/usr/local/bin/ir Epson ' . $cmd, 'salon'); } \ No newline at end of file diff --git a/scripts/lib/domoticz.php b/scripts/lib/domoticz.php index 8dfd12b..d92df81 100644 --- a/scripts/lib/domoticz.php +++ b/scripts/lib/domoticz.php @@ -23,12 +23,22 @@ function domoticzSwitch($device, $cmd, $type = 'light', $priority = false, $dela if ($cmd === 'Toogle' || $cmd === 'toogle' || $cmd === 'Toggle' || $cmd === 'toggle') { $cmd = 'Toggle'; } - if(is_bool($cmd)) { + if (is_bool($cmd)) { $cmd = $cmd ? 'On' : 'Off'; } return domoticzCmd(['idx' => $device, 'switchcmd' => $cmd, 'param' => 'switch' . $type, 'level' => '0', 'delay' => $delay], $priority); } +function domoticzSetLevel($device, $level, $priority = false) +{ + return domoticzCmd(['idx' => $device, 'switchcmd' => 'Set Level', 'param' => 'switchlight', 'level' => max(0, min(100, $level))], $priority); +} + +function domoticzGetLevel($device) +{ + return getDomoticzDeviceStatus($device, true, 'LevelInt'); +} + function domoticzCmd($command, $priority = false) { $redis = connectRedis(); @@ -48,10 +58,12 @@ function domoticzCmd($command, $priority = false) return true; } -function getDomoticzDeviceStatus($device, $force = false) +function getDomoticzDeviceStatus($device, $force = false, $key = 'Data') { + echo ':)'; $res = runDomoticzCommand(['type' => 'devices', 'rid' => $device]); $res = json_decode($res->getBody(), true); + print_r($res); try { $update = new DateTime($res['result'][0]['LastUpdate']); $now = new DateTime(); @@ -60,5 +72,5 @@ function getDomoticzDeviceStatus($device, $force = false) } } catch (Exception $e) { } - return $res['result'][0]['Data']; + return $res['result'][0][$key]; } diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 61c834e..1ff58cc 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -437,6 +437,7 @@ function ping($ip, $timeout = 5, $port = 1817) function volume($volume, $increase = '', $device = null) { $d = $device === null ? config('VOLUME_DEVICE') : $device; + echo $d.';'.$volume.';'.$increase; if ($increase == ' ') { $increase = '+'; @@ -482,6 +483,8 @@ function volume($volume, $increase = '', $device = null) } case 'vlc': return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device); + case 'denonavr': + return denonAVRVolume($volume,$increase); } } diff --git a/scripts/lib/off.php b/scripts/lib/off.php index 548f65c..f3d2d30 100644 --- a/scripts/lib/off.php +++ b/scripts/lib/off.php @@ -25,6 +25,8 @@ function commonOff($device) function offSalon() { + epson(false); + denonAVROff(); shieldKillAll('salon'); shieldSleep('salon'); } diff --git a/scripts/lib/proc.php b/scripts/lib/proc.php index 733eacd..a039193 100644 --- a/scripts/lib/proc.php +++ b/scripts/lib/proc.php @@ -103,12 +103,14 @@ class proc protected function _parseLine($line) { - if ($this->tooLate($line)) { - return; - } + foreach ($this->_cases as $expected_text => $closure) { if (strpos($line, $expected_text)) { + if ($this->tooLate($line)) { + echo 'too late ' . $line . "\n"; + return; + } $closure(); } } @@ -126,6 +128,11 @@ class proc $t = mktime($hour, $min, $sec, $month, $day, date('Y')); $c = time(); - return $t < $c - 5 || $t > $c; + + $res = $t < $c - 5 || $t > $c; + if ($res) { + echo $c - $t . "\n"; + } + return $res; } } \ No newline at end of file diff --git a/scripts/lib/shield.php b/scripts/lib/shield.php index 7c39ac3..b69a7c0 100644 --- a/scripts/lib/shield.php +++ b/scripts/lib/shield.php @@ -40,7 +40,8 @@ function shieldRunActivity($device = null) if ($device['id'] === 'salon') { stopPlayersIn('salon', true, false); - + epson(true); + denonAVROn(); } else if ($device['id'] === 'bureau' || $device['id'] === 'bureausun') { stopPlayersIn('bureau', true, false); if ($onlySound) { diff --git a/scripts/shield.php b/scripts/shield.php index 4c5d366..b5969d7 100644 --- a/scripts/shield.php +++ b/scripts/shield.php @@ -32,5 +32,7 @@ if (isset($_GET['key'])) { shieldMyCanal($e[1], $e[0]); } else if (isset($_GET['runappback'])) { shieldRunAppAndBackHome($_GET['runappback']); +}else if(isset($_GET['netflix'])){ + shieldNetflix(); } echo ''; \ No newline at end of file diff --git a/servers/logcat.php b/servers/logcat.php index ff6f8a9..20b16a6 100644 --- a/servers/logcat.php +++ b/servers/logcat.php @@ -28,15 +28,19 @@ $cases = [ } }, 'WindowManager: handleComboKeys keyCode: 25, keyAction: 1' => function () use ($device) { + echo 'volume-down' . "\n"; if ($device === 'bureau') { - echo 'volume-down' . "\n"; volume('3', '-', 'harmony'); + }else if($device==='salon'){ + volume('2', '-', 'denonavr'); } }, 'WindowManager: handleComboKeys keyCode: 24, keyAction: 1' => function () use ($device) { + echo 'volume-up' . "\n"; if ($device === 'bureau') { - echo 'volume-up' . "\n"; volume('3', '+', 'harmony'); + }else if($device==='salon'){ + volume('2', '+', 'denonavr'); } } ]; -- 2.39.5