Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Climate Devices v1 #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class BannerCard extends LitElement {
return this.renderDomainCover(options);
case "media_player":
return this.renderDomainMediaPlayer(options);
case "climate":
return this.renderDomainClimate(options);
}
}
return this.renderDomainDefault(options);
Expand Down Expand Up @@ -381,6 +383,45 @@ class BannerCard extends LitElement {
</div>
`;
}

renderDomainClimate(options) {
let entity_id = options.entity.split(".")[1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please camelCase variables

let thermostatTemperature = options.attributes.temperature;
let callClimateService = (options) => {
this._hass.callService("climate", "set_temperature", { "entity_id": options.entity, "temperature": options.attributes.temperature });
};
let onThermostatArrowClick = (diff) => {
clearTimeout(this._updateThermostateTemperatureTimeout);
options.attributes.temperature += diff;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the passed state object is not a good idea. A pure HA state object has a single source or truth, but when modifying it it gets confusing. I get that waiting for state changes to come back from HA takes too long for climate devices though. Perhaps keeping a this.stagedChanges = { [entityId]: { temperature: newTemperature } } or something similar could work. It would have to for example use a timestamp that is used in set hass (){} to clear the staged changes once a newer value comes from HA.

this.hass = this._hass;
this._updateThermostateTemperatureTimeout = setTimeout(callClimateService, 3000, options);
};
let onThermostatArrowUpClick = () => {
onThermostatArrowClick(0.5);
};
let onThermostatArrowDownClick = () => {
onThermostatArrowClick(-0.5);
};
return html`
<div class="entity-state" style="${this.grid(options.size)}">
<span class="entity-name">${options.name}</span>
<span class="entity-value ${entity_id}_editor">
<paper-icon-button
icon="hass:arrow-up"
role="button"
@click=${onThermostatArrowUpClick}
></paper-icon-button>
<span class="${entity_id}_value">${thermostatTemperature.toFixed(1)}</span>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value + the heading should be clickable to bring up the native more info dialog like it works for for example sensors.

<paper-icon-button
icon="hass:arrow-down"
role="button"
@click=${onThermostatArrowDownClick}
></paper-icon-button>
</span>
</span>
</div>
`;
}

getCardSize() {
return 3;
Expand Down