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

feat(lock): support open #321

Merged
merged 4 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
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
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