Skip to content

Commit

Permalink
Add more info card for thermostat. Fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Feb 28, 2015
1 parent b2b82d9 commit bbe19cb
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 23 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "3a8d2dfc420434e255e0c818cb384515"
VERSION = "30729f23c19a66d9364d78b2379867cc"
8 changes: 4 additions & 4 deletions homeassistant/components/frontend/www_static/frontend.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 29 additions & 16 deletions homeassistant/components/thermostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

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"
Expand All @@ -34,16 +33,26 @@

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):
Expand Down Expand Up @@ -90,13 +99,20 @@ def thermostat_service(service):
if not target_thermostats:
target_thermostats = thermostats.values()

if service.service == SERVICE_TURN_AWAY_MODE_ON:
for thermostat in target_thermostats:
thermostat.turn_away_mode_on()
if service.service == SERVICE_SET_AWAY_MODE:
away_mode = service.data.get(ATTR_AWAY_MODE)

elif service.service == SERVICE_TURN_AWAY_MODE_OFF:
for thermostat in target_thermostats:
thermostat.turn_away_mode_off()
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()
else:
for thermostat in target_thermostats:
thermostat.turn_away_mode_off()

elif service.service == SERVICE_SET_TEMPERATURE:
temperature = util.convert(
Expand All @@ -112,10 +128,7 @@ def thermostat_service(service):
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)
Expand Down

0 comments on commit bbe19cb

Please sign in to comment.