Skip to content

Commit

Permalink
Add optional toggle for away mode, fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
nervetattoo committed Feb 9, 2019
1 parent e8ec30f commit 6ee5605
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ custom_updater:
- `cool`: _string_ Use this icon for state cool
- `step_size` _number_: Override the default 0.5 step size for increasing/decreasing the temperature
- `hide` _object_: Control specifically information fields to show. Defaults to showing everything
- `temperature`: _bool_
- `state`: _bool_
- `mode`: _bool_
- `temperature`: _bool_ (Default to `false`)
- `state`: _bool_ (Default to `false`)
- `mode`: _bool_ (Default to `false`)
- `away`: _bool_ (Default to `true`)
- `sensors` _array_
- `entity` _string_: A sensor value entity id
- `attribute` _string_: The key for an attribute provided by the main entity (for example `min_temp`)
Expand Down
26 changes: 25 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const DEFAULT_HIDE = {
temperature: false,
state: false,
mode: false,
away: true,
}

class SimpleThermostat extends LitElement {
Expand Down Expand Up @@ -101,7 +102,7 @@ class SimpleThermostat extends LitElement {
}

if (this.config.hide) {
this._hide = { ...DEFAULT_HIDE, ...this.config.hide }
this._hide = { ...this._hide, ...this.config.hide }
}

if (typeof this.config.name === 'string') {
Expand Down Expand Up @@ -160,6 +161,7 @@ class SimpleThermostat extends LitElement {
current_temperature: current,
operation_list: operations = [],
operation_mode: operation,
...attributes
},
} = entity
const unit = this._hass.config.unit_system.temperature
Expand All @@ -171,6 +173,7 @@ class SimpleThermostat extends LitElement {
_hide.state
? null
: this.renderInfoItem(this.localize(state, 'state.climate.'), 'State'),
_hide.away ? null : this.renderAwayToggle(attributes.away_mode),
_hide.mode ? null : this.renderModeSelector(operations, operation),
sensors.map(({ name, state }) => {
return state && this.renderInfoItem(state, name)
Expand Down Expand Up @@ -288,6 +291,27 @@ class SimpleThermostat extends LitElement {
`
}

renderAwayToggle(state) {
return html`
<tr>
<th>${this.localize('ui.card.climate.away_mode')}</th>
<td>
<paper-toggle-button
?checked=${state === 'on'}
@click=${
() => {
this._hass.callService('climate', 'set_away_mode', {
entity_id: this.config.entity,
away_mode: !(state === 'on'),
})
}
}
/>
</td>
</tr>
`
}

renderInfoItem(state, heading) {
if (!state) return

Expand Down

0 comments on commit 6ee5605

Please sign in to comment.