Skip to content

Commit

Permalink
feat(lock): support open (#321)
Browse files Browse the repository at this point in the history
* feat(lock): support open

* fix: open state
  • Loading branch information
acesyde authored Apr 15, 2022
1 parent ce8c4ee commit b5b76e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/cards/lock-card/controls/lock-buttons-control.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { computeRTL, HomeAssistant } from "custom-card-helpers";
import { html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators.js";
import { supportsFeature } from "../../../ha/common/entity/supports-feature";
import { isAvailable } from "../../../ha/data/entity";
import { LockEntity } from "../../../ha/data/lock";
import { LockEntity, LOCK_SUPPORT_OPEN } from "../../../ha/data/lock";
import setupCustomlocalize from "../../../localize";
import { isActionPending, isLocked, isUnlocked } from "../utils";

interface LockButton {
icon: string;
title?: string;
serviceName?: string;
isVisible: (entity: LockEntity) => boolean;
isDisabled: (entity: LockEntity) => boolean;
Expand All @@ -15,12 +18,14 @@ interface LockButton {
export const LOCK_BUTTONS: LockButton[] = [
{
icon: "mdi:lock",
title: "lock",
serviceName: "lock",
isVisible: (entity) => isUnlocked(entity),
isDisabled: () => false,
},
{
icon: "mdi:lock-open",
title: "unlock",
serviceName: "unlock",
isVisible: (entity) => isLocked(entity),
isDisabled: () => false,
Expand All @@ -30,6 +35,13 @@ export const LOCK_BUTTONS: LockButton[] = [
isVisible: (entity) => isActionPending(entity),
isDisabled: () => true,
},
{
icon: "mdi:door-open",
title: "open",
serviceName: "open",
isVisible: (entity) => supportsFeature(entity, LOCK_SUPPORT_OPEN) && isUnlocked(entity),
isDisabled: (entity) => isActionPending(entity),
},
];

@customElement("mushroom-lock-buttons-control")
Expand All @@ -50,6 +62,7 @@ export class LockButtonsControl extends LitElement {

protected render(): TemplateResult {
const rtl = computeRTL(this.hass);
const customLocalize = setupCustomlocalize(this.hass!);

return html`
<mushroom-button-group .fill=${this.fill} .?rtl=${rtl}
Expand All @@ -58,6 +71,9 @@ export class LockButtonsControl extends LitElement {
<mushroom-button
.icon=${item.icon}
.entry=${item}
.title=${item.title
? customLocalize(`editor.card.lock.${item.title}`)
: ""}
.disabled=${!isAvailable(this.entity) || item.isDisabled(this.entity)}
@click=${this.callService}
></mushroom-button>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { property, customElement } from "lit/decorators.js";
@customElement("mushroom-button")
export class Button extends LitElement {
@property() public icon: string = "";
@property() public title: string = "";
@property({ type: Boolean }) public disabled: boolean = false;

protected render(): TemplateResult {
return html`
<button type="button" class="button" .disabled=${this.disabled}>
<button type="button" class="button" .title=${this.title} .disabled=${this.disabled}>
<ha-icon .icon=${this.icon} />
</button>
`;
Expand Down
5 changes: 5 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
"volume_set": "Volume level",
"volume_mute": "Mute"
}
},
"lock": {
"lock": "Lock",
"unlock": "Unlock",
"open": "Open"
}
},
"chip": {
Expand Down
5 changes: 5 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
"volume_set": "Niveau de volume",
"volume_mute": "Muet"
}
},
"lock": {
"lock": "Verrouiller",
"unlock": "Déverrouiller",
"open": "Ouvrir"
}
},
"chip": {
Expand Down

0 comments on commit b5b76e5

Please sign in to comment.