Included support for temperature/humidity display on weather widget from sensor events
This commit is contained in:
parent
e4269a8d5d
commit
20a9224ab5
3 changed files with 32 additions and 3 deletions
|
@ -16,3 +16,8 @@ h1.temperature {
|
|||
font-size: 22px;
|
||||
}
|
||||
|
||||
.widget.date-time-weather * > .sensor-temperature,
|
||||
.widget.date-time-weather * > .sensor-humidity {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -11,8 +11,12 @@
|
|||
|
||||
<div class="forecast" data-bind="forecast"></div>
|
||||
|
||||
<!-- <p class="sensor-temperature"> -->
|
||||
<!-- <span data-bind="sensor-temperature">N/A</span>° -->
|
||||
<!-- </p> -->
|
||||
<div class="sensor-temperature">
|
||||
Sensor temperature: <span data-bind="sensor-temperature">N/A</span>°
|
||||
</div>
|
||||
|
||||
<div class="sensor-humidity">
|
||||
Sensor humidity: <span data-bind="sensor-humidity">N/A</span>%
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue