Add more info card for thermostat. Fixes #28

pull/23/merge
Paulus Schoutsen 2015-02-28 08:36:37 -08:00
parent b2b82d955c
commit bbe19cbbb0
7 changed files with 153 additions and 23 deletions

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "3a8d2dfc420434e255e0c818cb384515"
VERSION = "30729f23c19a66d9364d78b2379867cc"

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit 9b5c89e05277c276c941166c582d2cb5159e9425
Subproject commit 2f96b21d42c6b1c01a235b39fbbd2e0cf1b8d651

View File

@ -5,6 +5,7 @@
<link rel="import" href="more-info-group.html">
<link rel="import" href="more-info-sun.html">
<link rel="import" href="more-info-configurator.html">
<link rel="import" href="more-info-thermostat.html">
<polymer-element name="more-info-content" attributes="stateObj">
<template>

View File

@ -0,0 +1,114 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-slider/paper-slider.html">
<link rel="import" href="../bower_components/paper-toggle-button/paper-toggle-button.html">
<polymer-element name="more-info-thermostat" attributes="stateObj">
<template>
<style>
paper-slider {
width: 100%;
}
paper-slider::shadow #sliderKnobInner,
paper-slider::shadow #sliderBar::shadow #activeProgress {
background-color: #039be5;
}
.away-mode-toggle {
display: none;
margin-top: 16px;
}
:host-context(.has-away_mode) .away-mode-toggle {
display: block;
}
</style>
<div>
<div>
<div>Target Temperature</div>
<paper-slider
min="{{tempMin}}" max="{{tempMax}}"
value='{{targetTemperatureSliderValue}}' pin
on-change="{{targetTemperatureSliderChanged}}">
</paper-slider>
</div>
<div class='away-mode-toggle'>
<div center horizontal layout>
<div flex>Away Mode</div>
<paper-toggle-button
checked="{{awayToggleChecked}}"
on-change="{{toggleChanged}}">
</paper-toggle-button>
</div>
</div>
</div>
</template>
<script>
var constants = window.hass.constants;
Polymer({
tempMin: 10,
tempMax: 40,
targetTemperatureSliderValue: 0,
awayToggleChecked: false,
observe: {
'stateObj.attributes.away_mode': 'awayChanged'
},
stateObjChanged: function(oldVal, newVal) {
this.targetTemperatureSliderValue = this.stateObj.state;
if (this.stateObj.attributes.unit_of_measurement === constants.UNIT_TEMP_F) {
this.tempMin = 45;
this.tempMax = 95;
} else {
this.tempMin = 7;
this.tempMax = 35;
}
},
targetTemperatureSliderChanged: function(ev, details, target) {
var temp = parseInt(target.value);
if(isNaN(temp)) return;
serviceActions.callService("thermostat", "set_temperature", {
entity_id: this.stateObj.entityId,
temperature: temp
});
},
toggleChanged: function(ev) {
var newVal = ev.target.checked;
if(newVal && this.stateObj.attributes.away_mode === 'off') {
this.service_set_away(true);
} else if(!newVal && this.stateObj.attributes.away_mode === 'on') {
this.service_set_away(false);
}
},
awayChanged: function(oldVal, newVal) {
this.awayToggleChecked = newVal == 'on';
},
service_set_away: function(away_mode) {
// We call stateChanged after a successful call to re-sync the toggle
// with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
serviceActions.callService(
'thermostat', 'set_away_mode',
{entity_id: this.stateObj.entityId, away_mode: away_mode})
.then(function() {
this.awayChanged(null, this.stateObj.attributes.away_mode);
}.bind(this));
},
});
</script>
</polymer-element>

View File

@ -3,7 +3,9 @@
<script>
(function() {
var DOMAINS_WITH_CARD = ['thermostat', 'configurator'];
var DOMAINS_WITH_MORE_INFO = ['light', 'group', 'sun', 'configurator'];
var DOMAINS_WITH_MORE_INFO = [
'light', 'group', 'sun', 'configurator', 'thermostat'
];
// Register some polymer filters

View File

@ -22,8 +22,7 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
DEPENDENCIES = []
SERVICE_TURN_AWAY_MODE_ON = "turn_away_mode_on"
SERVICE_TURN_AWAY_MODE_OFF = "turn_away_mode_off"
SERVICE_SET_AWAY_MODE = "set_away_mode"
SERVICE_SET_TEMPERATURE = "set_temperature"
ATTR_CURRENT_TEMPERATURE = "current_temperature"
@ -34,16 +33,26 @@ _LOGGER = logging.getLogger(__name__)
def turn_away_mode_on(hass, entity_id=None):
""" Turn all or specified thermostat away mode on. """
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
data = {
ATTR_AWAY_MODE: True
}
hass.services.call(DOMAIN, SERVICE_TURN_AWAY_MODE_ON, data)
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
def turn_away_mode_off(hass, entity_id=None):
""" Turn all or specified thermostat away mode off. """
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
data = {
ATTR_AWAY_MODE: False
}
hass.services.call(DOMAIN, SERVICE_TURN_AWAY_MODE_OFF, data)
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
def set_temperature(hass, temperature, entity_id=None):
@ -90,11 +99,18 @@ def setup(hass, config):
if not target_thermostats:
target_thermostats = thermostats.values()
if service.service == SERVICE_TURN_AWAY_MODE_ON:
if service.service == SERVICE_SET_AWAY_MODE:
away_mode = service.data.get(ATTR_AWAY_MODE)
if away_mode is None:
_LOGGER.error(
"Received call to %s without attribute %s",
SERVICE_SET_AWAY_MODE, ATTR_AWAY_MODE)
elif away_mode:
for thermostat in target_thermostats:
thermostat.turn_away_mode_on()
elif service.service == SERVICE_TURN_AWAY_MODE_OFF:
else:
for thermostat in target_thermostats:
thermostat.turn_away_mode_off()
@ -112,10 +128,7 @@ def setup(hass, config):
thermostat.update_ha_state(hass, True)
hass.services.register(
DOMAIN, SERVICE_TURN_AWAY_MODE_OFF, thermostat_service)
hass.services.register(
DOMAIN, SERVICE_TURN_AWAY_MODE_ON, thermostat_service)
DOMAIN, SERVICE_SET_AWAY_MODE, thermostat_service)
hass.services.register(
DOMAIN, SERVICE_SET_TEMPERATURE, thermostat_service)