From bc43b001320daf02fa41cc2d5744f2f572dd7f77 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 14 Nov 2022 09:37:12 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 24 +++++++++++++----------- config/water.php | 2 +- scripts/hotwater.php | 2 +- scripts/lib/redis.php | 4 ++-- scripts/lib/scenes.php | 3 +++ scripts/lib/switchbot.php | 24 +++++++++++++----------- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 044a998..9a82287 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,9 @@ - - + + + @@ -1174,14 +1175,8 @@ - - - - 1639205467698 - 1639302540066 @@ -1519,7 +1514,14 @@ - diff --git a/config/water.php b/config/water.php index ac998a1..4f68275 100644 --- a/config/water.php +++ b/config/water.php @@ -1,7 +1,7 @@ 'light', 'scene' => 'sdb/hotwater/auto', 'label' => 'Auto'], + ['type' => 'light', 'scene' => 'sdb/hotwater/auto/force', 'label' => 'Auto'], ['type' => 'light', 'scene' => 'sdb/hotwater/eco', 'label' => 'Eco'], ['type' => 'light', 'scene' => 'sdb/hotwater/max', 'label' => 'Max'], ['type' => 'light', 'scene' => 'sdb/hotwater/off', 'label' => 'Off'], diff --git a/scripts/hotwater.php b/scripts/hotwater.php index 00f85ba..b9e52d2 100644 --- a/scripts/hotwater.php +++ b/scripts/hotwater.php @@ -1,7 +1,7 @@ exists($key)) { + if ($force || !$client->exists($key)) { try { $data = call_user_func($closure); } catch (Exception $e) { diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 3aa03da..05f3650 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -758,6 +758,9 @@ $scenes = [ 'sdb/hotwater/auto' => [ ['type' => 'function', 'function' => 'hotwaterAutoMode', 'args' => ['1']], ], + 'sdb/hotwater/auto/force' => [ + ['type' => 'function', 'function' => 'hotwaterAutoMode', 'args' => ['1',true]], + ], 'sdb/hotwater/eco' => [ ['type' => 'function', 'function' => 'hotwaterAutoMode', 'args' => ['0']], ['type' => 'function', 'function' => 'hotwater', 'args' => ['1']], diff --git a/scripts/lib/switchbot.php b/scripts/lib/switchbot.php index 6879c75..05ee083 100644 --- a/scripts/lib/switchbot.php +++ b/scripts/lib/switchbot.php @@ -11,29 +11,32 @@ function switchbot($device, $command = 'press', $rpi = 'sdb') return $res; } -function hotwaterAutoMode($mode) +function hotwaterAutoMode($mode, $force = false) { $mode = $mode ? '1' : '0'; setState('hotwater_auto_mode', $mode); if ($mode) { - hotwaterCheckMode(); + hotwaterCheckMode($force); } } -function hotwaterCheckMode() +function hotwaterCheckMode($force = false) { if (getState('hotwater_auto_mode', '1') == '0') { return; } + $jerome = isJerome(true, $force); + $vincent = isVincent($force); + $h = date('G'); $d = date('N'); $isWeek = $d < 6; - $maxLevel = isJerome() ? "2" : '1'; + $maxLevel = $jerome ? "2" : '1'; $ecomode = (int)getState('ecomode', '0'); - if (!isVincent()) { + if (!isVincent($force)) { $hot = '1'; } else { if (getSqueezePlayerStatus('Salle de bains')) { @@ -53,7 +56,7 @@ function hotwaterCheckMode() } } } - echo "\n\n" . 'V:' . isVincent() . '/J:' . isJerome() . '/H:' . $h . '/D:' . $d . '/W:' . $hot . "\n\n"; + echo "\n\n" . 'V:' . $vincent . '/J:' . $jerome . '/H:' . $h . '/D:' . $d . '/W:' . $hot . "\n\n"; hotwater($hot); } @@ -64,7 +67,6 @@ function hotwater($newState) // 1 : ECO // 2 : MAX - echo getState('hotwater_auto_mode', '1') . '::' . getState('hotwater_change', '0') . '::' . getState('hotwater', '1'); $changing = getState('hotwater_change', '0'); $limit = time() - 300; @@ -94,11 +96,11 @@ function hotwater($newState) return $res; } -function isVincent() +function isVincent($force = false) { return remember('vincent_in_paris', 3600, function () { return _isVincent(); - }, true); + }, true, $force); } function _isVincent() @@ -113,13 +115,13 @@ function _isVincent() return true; } -function isJerome($strict = true) +function isJerome($strict = true, $force = false) { $key = 'jerome_in_paris' . ($strict ? '' : '_1'); return remember($key, 3600, function () use ($strict) { return _isJerome($strict); - }, true); + }, true, $force); } function _isJerome($strict = true) -- 2.39.5