From a812369d6601d6e5f6c586a25daad59201c3130b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sun, 3 Sep 2023 16:52:37 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 14 +- config/entree.php | 26 +- js/home.js | 33 +++ scripts/lib/lib.php | 8 +- scripts/lib/weatherstation.php | 470 +++++++++++++++++---------------- scripts/lib/windows.php | 71 +++++ scripts/lock.php | 13 + style/style.css | 14 + style/style.less | 22 +- 9 files changed, 421 insertions(+), 250 deletions(-) create mode 100644 scripts/lib/windows.php create mode 100644 scripts/lock.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84e8fab..6141cba 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,15 @@ + + - + + + + + + diff --git a/config/entree.php b/config/entree.php index 155dda4..9cf7134 100644 --- a/config/entree.php +++ b/config/entree.php @@ -5,23 +5,23 @@ config('SQUEEZEBOX_PLAYER', 'Cuisine'); config('SLEEPSCREEN', 15); config('SCREENSAVER_BRIGHTNESS', 100); config('SLEEPTYPE', 'screensaver'); -config('SCREENSAVER','weatherstation'); +config('SCREENSAVER', 'weatherstation'); config('VOLUME_DEVICE', 'SqueezeboxPlayer'); -config('VOLUME_STEP',5); -config('HIDEMASK_TIMEOUT',250); -config('THEME','#000000'); +config('VOLUME_STEP', 5); +config('HIDEMASK_TIMEOUT', 250); +config('THEME', '#000000'); if (DISPLAYINTERFACE) { - if (!isset($shortcuts)) { - $shortcuts = []; - } + if (!isset($shortcuts)) { + $shortcuts = []; + } - $c = home(); - $shortcuts['lights'] = $c['all']; - $favoriteslights = $c['favorites']; - array_splice($favoriteslights, 3, 0, [['type' => 'velib'], ['type' => 'traffic']]); + $c = home(); + $shortcuts['lights'] = $c['all']; + $favoriteslights = $c['favorites']; + array_splice($favoriteslights, 3, 0, [['type' => 'lock'], ['type' => 'velib'], ['type' => 'traffic']]); - $nav=['home','lights','music','coffee','switch','settings','alert','off']; + $nav = ['home', 'lights', 'music', 'coffee', 'switch', 'settings', 'alert', 'off']; - include "default.php"; + include "default.php"; } diff --git a/js/home.js b/js/home.js index 799e047..8607a6a 100644 --- a/js/home.js +++ b/js/home.js @@ -399,6 +399,7 @@ $(function () { initWeather(); initTraffic(); initVelib(); + initLocks(); setTimeout(function () { console.log('init'); @@ -706,6 +707,38 @@ function initTraffic() { updateTraffic(false); } +function initLocks() { + $(document).on('click', ".lock", function () { + displayLoader($(this)); + updateLocks(); + }); + setInterval(function () { + updateLocks(); + }, 1000 * 15); + updateLocks(); +} + +function updateLocks() { + var t = $(".lock"); + if (t.length == 0) { + return; + } + let url = 'scripts/lock.php'; + $.get(url + '?' + new Date().getTime(), function (data) { + if (data.secured) { + $(t).addClass('secured'); + } else { + $(t).removeClass('secured'); + } + t.find('.icon').text(data.icon); + t.attr('data-init', '1'); + resize(); + hideLoader(); + }).fail(function () { + hideLoader(); + }); +} + function updateTraffic(force) { var t = $(".traffic"); if (t.length == 0) { diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 016d690..fd94442 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -55,6 +55,7 @@ require_once ROOT . '/scripts/lib/wol.php'; require_once ROOT . '/scripts/lib/switchbot.php'; require_once ROOT . '/scripts/lib/ical.php'; require_once ROOT . '/scripts/lib/klarstein.php'; +require_once ROOT . '/scripts/lib/windows.php'; profile('Loaded libraries', __FILE__, __LINE__); @@ -308,7 +309,12 @@ function shortcut($s, $hash)
de bouchons
'; - } elseif ($s['type'] == 'velib') { + } else if($s['type']==='lock'){ + $attrs['class'] = $s['type'] . ' info'; + $attrs['data-init'] = "0"; + $attrs['data-init-function'] = "updateLocks"; + $s['label']='
'; + }elseif ($s['type'] == 'velib') { $attrs['class'] = $s['type'] . ' info'; $attrs['data-init'] = "0"; $attrs['data-init-function'] = "updateVelib"; diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index 11255a5..4488b71 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -1,258 +1,266 @@ '; - $res .= '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['icon']) . '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; - $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . $weather['min'] . '°C
'; - $res .= '
' . $weather['outdoor_temp'] . '°C ' . $weather['temp'] . '°C
'; - $res .= '
' . $weather['max'] . '°C
'; - $res .= '
'; - $res .= '
'; - $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $pressure . ' hPa | ' . $weather['outdoor_humidity'] . '%'; - $res .= '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . $weather['backyard_temp'] . ' °C' . $weather['backyard_humidity'] . '%' . $weather['kitchen_temp'] . ' °C' . $weather['kitchen_humidity'] . '%
' . $weather['livingroom_temp'] . ' °C' . $weather['livingroom_humidity'] . '%' . $weather['office_temp'] . ' °C' . $weather['office_humidity'] . '%
' . $weather['wc_temp'] . ' °C' . $weather['wc_humidity'] . '%' . $weather['bedroom_temp'] . ' °C' . $weather['bedroom_humidity'] . '%
' . $weather['bathroom_temp'] . ' °C' . $weather['bathroom_humidity'] . '%' . $weather['cellar_temp'] . ' °C' . $weather['cellar_humidity'] . '%
'; - $res .= '
'; - $res .= '
'; - foreach ($weather['forecasts'] as $forecast) { - $res .= '
'; - $res .= '
' . $forecast['day'] . '
'; - $res .= '
' . accuweatherIcon($forecast['nightIcon']) . '
'; - $res .= '
' . accuweatherIcon($forecast['dayIcon']) . '
'; - $res .= '
' . $forecast['min'] . '°C
'; - $res .= '
' . $forecast['max'] . '°C
'; - $res .= '
'; - } - $res .= '
'; - - $res .= '
'; - $res .= _curve($weather, 'sun'); - $res .= _curve($weather, 'moon'); - $res .= '
'; - $res .= '
'; - - return $res; +function weatherStationScreenSaver() +{ + $weather = json_decode(file_get_contents(ROOT . '/cache/weather.json'), true); + + $pressureTendency = $weather['pressureTendency'] == 'F' ? 'down' : 'up'; + $pressure = $weather['outdoor_pressure'] == '--' ? $weather['backyard_pressure'] : $weather['outdoor_pressure']; + + $res = '
'; + $res .= '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['icon']) . '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; + $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . $weather['min'] . '°C
'; + $res .= '
' . $weather['outdoor_temp'] . '°C ' . $weather['temp'] . '°C
'; + $res .= '
' . $weather['max'] . '°C
'; + $res .= '
'; + $res .= '
'; + $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $pressure . ' hPa | ' . $weather['outdoor_humidity'] . '%'; + $res .= '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . $weather['backyard_temp'] . ' °C' . $weather['backyard_humidity'] . '%' . $weather['kitchen_temp'] . ' °C' . $weather['kitchen_humidity'] . '%
' . $weather['livingroom_temp'] . ' °C' . $weather['livingroom_humidity'] . '%' . $weather['office_temp'] . ' °C' . $weather['office_humidity'] . '%
' . $weather['wc_temp'] . ' °C' . $weather['wc_humidity'] . '%' . $weather['bedroom_temp'] . ' °C' . $weather['bedroom_humidity'] . '%
' . $weather['bathroom_temp'] . ' °C' . $weather['bathroom_humidity'] . '%' . $weather['cellar_temp'] . ' °C' . $weather['cellar_humidity'] . '%
'; + $res .= '
'; + $res .= '
'; + foreach ($weather['forecasts'] as $forecast) { + $res .= '
'; + $res .= '
' . $forecast['day'] . '
'; + $res .= '
' . accuweatherIcon($forecast['nightIcon']) . '
'; + $res .= '
' . accuweatherIcon($forecast['dayIcon']) . '
'; + $res .= '
' . $forecast['min'] . '°C
'; + $res .= '
' . $forecast['max'] . '°C
'; + $res .= '
'; + } + $res .= '
'; + + $res .= '
'; + $res .= _curve($weather, 'sun'); + $res .= _curve($weather, 'moon'); + $res .= '
'; + $res .= '
'; + + return $res; } -function _curve($weather, $curve) { - $time = time(); - - if ($curve == 'sun') { - $set = $weather['sunset']; - $rise = $weather['sunrise']; - $icon = '/images/weather/sun.svg'; - $radius = 75; - $pointXOffset = 44; - $pointYOffset = 33; - } else { - $set = $weather['moonset']; - $rise = $weather['moonrise']; - $icon = '/images/weather/moon/' . (round(($weather['moonage'] / 28) * 12) % 12) . '.svg'; - $radius = 50; - $pointXOffset = 33; - $pointYOffset = 21; - } - - $diameter = $radius * 2; - - $duration = 360 * (($set - $rise) / (3600 * 24)); - $riseAngle = (180 - $duration) / 2; - $setAngle = $riseAngle + $duration; - - //die('d '.$sunduration.';r '.$sunriseAngle.';s '.$sunsetAngle); - - $sunrisePos = getPosOnCircle($riseAngle, $radius, $pointXOffset, $pointYOffset); - $sunsetPos = getPosOnCircle($setAngle, $radius, $pointXOffset, $pointYOffset); - $sunangle = $riseAngle + (($time - $rise) / (3600 * 24)) * 360; - - $res = '
'; - $res .= '
'; - if ($curve === 'sun') { - $res .= '
'; - } else { - $res .= '
'; - } - $res .= '
'; - $res .= '
' . date('H:i', $rise) . '
'; - $res .= '
' . date('H:i', $set) . '
'; - $res .= '
'; - - return $res; +function _curve($weather, $curve) +{ + $time = time(); + + if ($curve == 'sun') { + $set = $weather['sunset']; + $rise = $weather['sunrise']; + $icon = '/images/weather/sun.svg'; + $radius = 75; + $pointXOffset = 44; + $pointYOffset = 33; + } else { + $set = $weather['moonset']; + $rise = $weather['moonrise']; + $icon = '/images/weather/moon/' . (round(($weather['moonage'] / 28) * 12) % 12) . '.svg'; + $radius = 50; + $pointXOffset = 33; + $pointYOffset = 21; + } + + $diameter = $radius * 2; + + $duration = 360 * (($set - $rise) / (3600 * 24)); + $riseAngle = (180 - $duration) / 2; + $setAngle = $riseAngle + $duration; + + //die('d '.$sunduration.';r '.$sunriseAngle.';s '.$sunsetAngle); + + $sunrisePos = getPosOnCircle($riseAngle, $radius, $pointXOffset, $pointYOffset); + $sunsetPos = getPosOnCircle($setAngle, $radius, $pointXOffset, $pointYOffset); + $sunangle = $riseAngle + (($time - $rise) / (3600 * 24)) * 360; + + $res = '
'; + $res .= '
'; + if ($curve === 'sun') { + $res .= '
'; + } else { + $res .= '
'; + } + $res .= '
'; + $res .= '
' . date('H:i', $rise) . '
'; + $res .= '
' . date('H:i', $set) . '
'; + $res .= '
'; + + return $res; } -function getPosOnCircle($angle, $radius, $x, $y) { - $angle -= 180; - $cos = $radius / 2 + (cos(deg2rad($angle)) * $radius); - $sin = $radius / 2 + (sin(deg2rad($angle)) * $radius); +function getPosOnCircle($angle, $radius, $x, $y) +{ + $angle -= 180; + $cos = $radius / 2 + (cos(deg2rad($angle)) * $radius); + $sin = $radius / 2 + (sin(deg2rad($angle)) * $radius); - return ['x' => $x + $cos, 'y' => $y + $sin]; + return ['x' => $x + $cos, 'y' => $y + $sin]; } -function accuweatherIcon($icon) { - return ''; - // return ''; +function accuweatherIcon($icon) +{ + return ''; + // return ''; } -function isDay() { - return getPeriodOfDay()['day']; +function isDay() +{ + return getPeriodOfDay()['day']; } -function getPeriodOfDay() { - $time = new DateTime('now', new DateTimeZone('Europe/Paris')); - $timestamp = $time->getTimestamp(); - $offset = $time->getOffset() / 3600; +function getPeriodOfDay() +{ + $time = new DateTime('now', new DateTimeZone('Europe/Paris')); + $timestamp = $time->getTimestamp(); + $offset = $time->getOffset() / 3600; - $hours = intval(date('H')); + $hours = intval(date('H')); - $sunrise = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset); - $sunset = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset); + $sunrise = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset); + $sunset = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset); - if ($timestamp > $sunset && $sunrise < $sunset) { - $sunrise += 3600 * 24; - } + if ($timestamp > $sunset && $sunrise < $sunset) { + $sunrise += 3600 * 24; + } - $start_twilight = $sunset - 3600; - $end_twilight = $sunset + 3600; + $start_twilight = $sunset - 3600; + $end_twilight = $sunset + 3600; - $start_dawn = $sunrise - 3600; - $end_dawn = $sunrise + 3600; + $start_dawn = $sunrise - 3600; + $end_dawn = $sunrise + 3600; - $day = !($timestamp < $sunrise || $timestamp >= $sunset); + $day = !($timestamp < $sunrise || $timestamp >= $sunset); - if ($timestamp >= $start_twilight && $timestamp < $end_twilight) { - $period = 'twilight'; - } else if ($timestamp >= $start_dawn && $timestamp < $end_dawn) { - $period = 'dawn'; - } else if ($day) { + if ($timestamp >= $start_twilight && $timestamp < $end_twilight) { + $period = 'twilight'; + } else if ($timestamp >= $start_dawn && $timestamp < $end_dawn) { + $period = 'dawn'; + } else if ($day) { - } else { - $period = 'night'; - } + } else { + $period = 'night'; + } - if ($day) { - $midday = ($sunset + $sunrise) / 2; - } else { + if ($day) { + $midday = ($sunset + $sunrise) / 2; + } else { - } + } + + return ['day' => $day, 'period' => $period]; +} - return ['day' => $day, 'period' => $period]; -} \ No newline at end of file diff --git a/scripts/lib/windows.php b/scripts/lib/windows.php new file mode 100644 index 0000000..576dd25 --- /dev/null +++ b/scripts/lib/windows.php @@ -0,0 +1,71 @@ + $sensor) { + if ($sensor['type'] !== 'window') { + continue; + } + if (haGetState($sensor['device']) === 'on') { + return true; + } + } + return false; +} + +function isSecured() +{ + foreach (sensors() as $name => $sensor) { + if (!$sensor['secure']) { + continue; + } + if (haGetState($sensor['device']) === 'on') { + return false; + } + } + return true; +} + +function needOpenWindows() +{ + return areWindowsClosed() && optimalWindowsOpening(); +} + +function optimalWindowsOpening() +{ + $summer = isSummer(); + $outdoor = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_temperature', 'sensor.w340001x_tempc']), 1); + $indoor = toNumber(haGetState(['sensor.meter_c7c3_temperature', 'sensor.thx1_w230150x_tempc']), 1); + $res = $indoor > $outdoor; + if ($summer) { + return $res; + } + return !$res; + + +} + +function areWindowsClosed() +{ + return !areWindowsOpened(); +} + +function needCloseWindows() +{ + return areWindowsOpened() && !optimalWindowsOpening(); +} + +function sensors() +{ + return [ + 'Chambre Est' => ['device' => 'binary_sensor.0x00124b0029344d11_contact', 'type' => 'window', 'secure' => true], + 'Chambre Ouest' => ['device' => 'binary_sensor.0x00124b002933740b_contact', 'type' => 'window', 'secure' => true], + 'Bureau' => ['device' => 'binary_sensor.0x00124b002933744d_contact', 'type' => 'window', 'secure' => true], + ]; +} \ No newline at end of file diff --git a/scripts/lock.php b/scripts/lock.php new file mode 100644 index 0000000..0ea8d99 --- /dev/null +++ b/scripts/lock.php @@ -0,0 +1,13 @@ + $secured ? '🔒' : '🔓', + 'secured' => $secured, + 'windows' => areWindowsOpened(), +]; + +header('content-type: application/json'); + +die(json_encode($res)); \ No newline at end of file diff --git a/style/style.css b/style/style.css index 8f0edbd..7121cf4 100644 --- a/style/style.css +++ b/style/style.css @@ -674,6 +674,20 @@ section accordion.closed { width: 100%; height: 100%; } +section .col > .info.lock { + background-color: rgba(204, 0, 0, 0.5); +} +section .col > .info.lock.secured { + background-color: rgba(0, 0, 0, 0.5); +} +section .col > .info.lock .icon { + position: absolute; + top: 0; + left: 0; + width: 100%; + opacity: 0.3; + font-size: 4em; +} .mm-spn { --mm-ocd-max-width: 440px; } diff --git a/style/style.less b/style/style.less index f8f5f22..dcae523 100644 --- a/style/style.less +++ b/style/style.less @@ -308,8 +308,8 @@ section { } } - &.nintendoswitch{ - background-color:#e60012; + &.nintendoswitch { + background-color: #e60012; } &.missing { @@ -541,6 +541,24 @@ section { } +section .col > .info.lock { + background-color: rgba(204, 0, 0, 0.5); + + &.secured { + background-color: rgba(0, 0, 0, 0.5); + } + + .icon { + position: absolute; + top: 0; + left: 0; + width: 100%; + opacity: 0.3; + font-size: 4em; + + } +} + @import "menu"; @import "remote"; \ No newline at end of file -- 2.39.5