Skip to content

Commit

Permalink
fix: Header toggle
Browse files Browse the repository at this point in the history
Fixes #239
  • Loading branch information
nervetattoo committed Apr 10, 2021
1 parent 5004a00 commit c9022e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ function renderFaults(faults, openEntityPopover) {
return html` <div class="faults">${faultHtml}</div>`
}

function renderToggle(toggle, toggleEntityChanged, openEntityPopover) {
function renderToggle(toggle, openEntityPopover, toggleEntityChanged) {
if (!toggle) return nothing

return html`
<div style="margin-left: auto;">
<span
class="clickable toggle-label"
@click="${() => openEntityPopover(toggle.entity)}"
@click=${() => openEntityPopover(toggle.entity.entity_id)}
>${toggle.label}
</span>
<ha-switch
Expand Down
16 changes: 10 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,17 @@ export default class SimpleThermostat extends LitElement {
`
}

toggleEntityChanged(ev: Event) {
if (!this.header) return
toggleEntityChanged = (ev: Event) => {
if (!this.header || !this?.header?.toggle) return

const el = ev.target as HTMLInputElement
const newVal = el.checked
this._hass.callService('homeassistant', newVal ? 'turn_on' : 'turn_off', {
entity_id: this.header?.toggle?.entity,
})
this._hass.callService(
'homeassistant',
el.checked ? 'turn_on' : 'turn_off',
{
entity_id: this.header?.toggle?.entity?.entity_id,
}
)
}

setTemperature(change: number, field: string) {
Expand Down

0 comments on commit c9022e4

Please sign in to comment.