Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
126 changes: 0 additions & 126 deletions src/components/ha-cover-controls.js

This file was deleted.

148 changes: 148 additions & 0 deletions src/components/ha-cover-controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {
css,
CSSResult,
customElement,
html,
internalProperty,
LitElement,
property,
TemplateResult,
} from "lit-element";
import { classMap } from "lit-html/directives/class-map";
import { HassEntity } from "home-assistant-js-websocket";

import { UNAVAILABLE } from "../data/entity";
import { HomeAssistant } from "../types";
import CoverEntity from "../util/cover-model";

import "./ha-icon-button";
Comment thread
iantrich marked this conversation as resolved.

@customElement("ha-cover-controls")
class HaCoverControls extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@internalProperty() private _stateObj!: HassEntity;

private _entityObj?: CoverEntity;

public set stateObj(stateObj: HassEntity) {
this._entityObj = new CoverEntity(this.hass, stateObj);
this._stateObj = stateObj;
}
Comment thread
iantrich marked this conversation as resolved.
Outdated

protected render(): TemplateResult {
if (!this._entityObj) {
return html``;
}

return html`
<div class="state">
<ha-icon-button
class=${classMap({
invisible: !this._entityObj.supportsOpen,
})}
.label=${this.hass.localize("ui.dialogs.more_info_control.open_cover")}
.icon=${this._computeOpenIcon()}
@click=${this._onOpenTap}
.disabled=${this._computeOpenDisabled()}
></ha-icon-button>
<ha-icon-button
class=${classMap({
invisible: !this._entityObj.supportsStop,
})}
.label=${this.hass.localize("ui.dialogs.more_info_control.stop_cover")}
icon="hass:stop"
@click=${this._onStopTap}
.disabled=${this._stateObj.state === UNAVAILABLE}
></ha-icon-button>
<ha-icon-button
class=${classMap({
invisible: !this._entityObj.supportsClose,
})}
.label=${this.hass.localize(
"ui.dialogs.more_info_control.close_cover"
)}
.icon=${this._computeCloseIcon()}
@click=${this._onCloseTap}
.disabled=${this._computeClosedDisabled()}
></ha-icon-button>
</div>
`;
}

private _computeOpenIcon(): string {
switch (this._stateObj.attributes.device_class) {
case "awning":
case "door":
case "gate":
return "hass:arrow-expand-horizontal";
default:
return "hass:arrow-up";
}
}

private _computeCloseIcon(): string {
switch (this._stateObj.attributes.device_class) {
case "awning":
case "door":
case "gate":
return "hass:arrow-collapse-horizontal";
default:
return "hass:arrow-down";
}
}
Comment thread
iantrich marked this conversation as resolved.
Outdated

private _computeOpenDisabled(): boolean {
if (this._stateObj.state === UNAVAILABLE) {
return true;
}
const assumedState = this._stateObj.attributes.assumed_state === true;
return (
(this._entityObj.isFullyOpen || this._entityObj.isOpening) &&
!assumedState
);
}

private _computeClosedDisabled(): boolean {
if (this._stateObj.state === UNAVAILABLE) {
return true;
}
const assumedState = this._stateObj.attributes.assumed_state === true;
return (
(this._entityObj.isFullyClosed || this._entityObj.isClosing) &&
!assumedState
);
}

private _onOpenTap(ev): void {
ev.stopPropagation();
this._entityObj.openCover();
}

private _onCloseTap(ev): void {
ev.stopPropagation();
this._entityObj.closeCover();
}

private _onStopTap(ev): void {
ev.stopPropagation();
this._entityObj.stopCover();
}

static get styles(): CSSResult {
return css`
.state {
white-space: nowrap;
}
.invisible {
Comment thread
iantrich marked this conversation as resolved.
Outdated
visibility: hidden !important;
}
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-cover-controls": HaCoverControls;
}
}
5 changes: 5 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@
},
"person": {
"create_zone": "Create zone from current location"
},
"cover": {
"open_cover": "Open cover",
"stop_cover": "Stop the cover from moving",
"close_cover": "Close cover"
}
},
"entity_registry": {
Expand Down