From 8f6fc53c6b5f8a52a20ee202ec3807c6fbb6dcd2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 13 Oct 2022 08:04:13 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 27 +++++++------------ scripts/lib/switchbot.php | 55 +++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8ec9af6..4128cb0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,16 +2,7 @@ - - - - - - - - - diff --git a/scripts/lib/switchbot.php b/scripts/lib/switchbot.php index f5f5f5f..b00a6b4 100644 --- a/scripts/lib/switchbot.php +++ b/scripts/lib/switchbot.php @@ -26,30 +26,33 @@ function hotwaterCheckMode() return; } - if (getSqueezePlayerStatus('Salle de bains')) { - $hot = '2'; - } else { - $h = date('G'); - $d = date('N'); - $isWeek = $d < 6; + $h = date('G'); + $d = date('N'); + $isWeek = $d < 6; - $ecomode = (int)getState('ecomode', '0'); + $ecomode = (int)getState('ecomode', '0'); - if (isJerome()) { - $weekColdHours = [0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23]; - if ($ecomode == 0) { - $hot = ($isWeek && in_array($h, $weekColdHours)) ? '0' : '1'; - } else if ($ecomode == 1) { - $hot = ($isWeek && $h >= 6 && $h <= 7) ? '1' : '0'; - } else if ($ecomode == 2) { + if (!isVincent()) { + $hot = 1; + } else { + if (getSqueezePlayerStatus('Salle de bains')) { + $hot = '2'; + } else { + if (isJerome()) { + $weekColdHours = [0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23]; + if ($ecomode == 0) { + $hot = ($isWeek && in_array($h, $weekColdHours)) ? '0' : '1'; + } else if ($ecomode == 1) { + $hot = ($isWeek && $h >= 6 && $h <= 7) ? '1' : '0'; + } else if ($ecomode == 2) { + $hot = '0'; + } + } else { $hot = '0'; } - } else { - $hot = '0'; } - - echo "\n\n" . 'J:' . isJerome() . 'H:' . $h . '/D:' . $d . '/W:' . $hot . "\n\n"; } + echo "\n\n" . 'V:' . isVincent() . '/J:' . isJerome() . '/H:' . $h . '/D:' . $d . '/W:' . $hot . "\n\n"; hotwater($hot); } @@ -91,7 +94,21 @@ function hotwater($newState) function isVincent() { + return remember('vincent_in_paris', 3600, function () { + return _isVincent(); + }); +} +function _isVincent() +{ + $today = new DateTime('now'); + $events = searchIcalEventDay('dplacements-jrme', $today); + foreach ($events as $event) { + if (stristr($event['data']['SUMMARY'], '(V)')) { + return false; + } + } + return true; } function isJerome() @@ -112,7 +129,7 @@ function _isJerome() $dates = [$yesterday, $today, $tomorrow]; foreach ($dates as $date) { - $events = searchIcalEventDay('dplacements-jrme', $today); + $events = searchIcalEventDay('dplacements-jrme', $date); $count = 0; foreach ($events as $event) { if (stristr($event['data']['SUMMARY'], '(V)')) { -- 2.39.5