From 20a9224ab5ffcc529177806277501c67854bd9a2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 7 May 2018 18:55:50 +0200 Subject: [PATCH] Included support for temperature/humidity display on weather widget from sensor events --- .../static/css/widgets/date-time-weather.css | 5 +++++ .../static/js/widgets/date-time-weather.js | 20 +++++++++++++++++++ .../templates/widgets/date-time-weather.html | 10 +++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/platypush/backend/http/static/css/widgets/date-time-weather.css b/platypush/backend/http/static/css/widgets/date-time-weather.css index 3b01120076..49fcf029e5 100644 --- a/platypush/backend/http/static/css/widgets/date-time-weather.css +++ b/platypush/backend/http/static/css/widgets/date-time-weather.css @@ -16,3 +16,8 @@ h1.temperature { font-size: 22px; } + .widget.date-time-weather * > .sensor-temperature, + .widget.date-time-weather * > .sensor-humidity { + display: none; + } + diff --git a/platypush/backend/http/static/js/widgets/date-time-weather.js b/platypush/backend/http/static/js/widgets/date-time-weather.js index 9b0ead879a..92b8dd516e 100644 --- a/platypush/backend/http/static/js/widgets/date-time-weather.js +++ b/platypush/backend/http/static/js/widgets/date-time-weather.js @@ -2,12 +2,22 @@ $(document).ready(function() { var $widget = $('.widget.date-time-weather'), $dateElement = $widget.find('[data-bind=date]'), $timeElement = $widget.find('[data-bind=time]'), + $sensorTempElement = $widget.find('[data-bind=sensor-temperature]'), + $sensorHumidityElement = $widget.find('[data-bind=sensor-humidity]'), $forecastElement = $widget.find('[data-bind=forecast]'), $tempElement = $widget.find('[data-bind=temperature]'); var onEvent = function(event) { if (event.args.type == 'platypush.message.event.weather.NewWeatherConditionEvent') { updateTemperature(event.args.temperature); + } else if (event.args.type == 'platypush.message.event.sensor.SensorDataChangeEvent') { + if ('temperature' in event.args) { + updateSensorTemperature(event.args.temperature); + } + + if ('humidity' in event.args) { + updateSensorHumidity(event.args.humidity); + } } }; @@ -15,6 +25,16 @@ $(document).ready(function() { $tempElement.text(Math.round(temperature)); }; + var updateSensorTemperature = function(temperature) { + $sensorTempElement.text(Math.round(temperature*10)/10); + $sensorTempElement.parent().show(); + }; + + var updateSensorHumidity = function(humidity) { + $sensorHumidityElement.text(Math.round(humidity)); + $sensorHumidityElement.parent().show(); + }; + var initEvents = function() { window.registerEventListener(onEvent); }; diff --git a/platypush/backend/http/templates/widgets/date-time-weather.html b/platypush/backend/http/templates/widgets/date-time-weather.html index 58aa45aaf9..bfe1483da2 100644 --- a/platypush/backend/http/templates/widgets/date-time-weather.html +++ b/platypush/backend/http/templates/widgets/date-time-weather.html @@ -11,8 +11,12 @@
- - - +
+ Sensor temperature: N/A° +
+ +
+ Sensor humidity: N/A% +