-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,286 additions
and
1,247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-typescript"] | ||
"presets": ["@babel/preset-typescript"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
.hass_dev/* | ||
package-lock.json | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
arrowParens: "always", | ||
bracketSpacing: true, | ||
bracketSameLine: false, | ||
endOfLine: "lf", | ||
printWidth: 80, | ||
semi: true, | ||
singleQuote: false, | ||
tabWidth: 4, | ||
trailingComma: "es5", | ||
useTabs: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,129 @@ | ||
import { | ||
fireEvent, | ||
HomeAssistant, | ||
LovelaceCardEditor, | ||
stateIcon, | ||
fireEvent, | ||
HomeAssistant, | ||
LovelaceCardEditor, | ||
stateIcon, | ||
} from "custom-card-helpers"; | ||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit"; | ||
import { customElement, property, state } from "lit/decorators.js"; | ||
import { assert, assign, object, optional, string } from "superstruct"; | ||
import { | ||
baseLovelaceCardConfig, | ||
configElementStyle, | ||
EditorTarget, | ||
baseLovelaceCardConfig, | ||
configElementStyle, | ||
EditorTarget, | ||
} from "../../utils/editor"; | ||
import { COVER_CARD_EDITOR_NAME } from "./const"; | ||
import { CoverCardConfig } from "./cover-card"; | ||
|
||
const DOMAINS = ["cover"]; | ||
|
||
const cardConfigStruct = assign( | ||
baseLovelaceCardConfig, | ||
object({ | ||
entity: string(), | ||
icon: optional(string()), | ||
name: optional(string()), | ||
}) | ||
baseLovelaceCardConfig, | ||
object({ | ||
entity: string(), | ||
icon: optional(string()), | ||
name: optional(string()), | ||
}) | ||
); | ||
|
||
@customElement(COVER_CARD_EDITOR_NAME) | ||
export class CoverCardEditor extends LitElement implements LovelaceCardEditor { | ||
@property({ attribute: false }) public hass?: HomeAssistant; | ||
@property({ attribute: false }) public hass?: HomeAssistant; | ||
|
||
@state() private _config?: CoverCardConfig; | ||
@state() private _config?: CoverCardConfig; | ||
|
||
public setConfig(config: CoverCardConfig): void { | ||
assert(config, cardConfigStruct); | ||
this._config = config; | ||
} | ||
|
||
get _entity(): string { | ||
return this._config!.entity || ""; | ||
} | ||
public setConfig(config: CoverCardConfig): void { | ||
assert(config, cardConfigStruct); | ||
this._config = config; | ||
} | ||
|
||
get _name(): string { | ||
return this._config!.name || ""; | ||
} | ||
get _entity(): string { | ||
return this._config!.entity || ""; | ||
} | ||
|
||
get _icon(): string { | ||
return this._config!.icon || ""; | ||
} | ||
get _name(): string { | ||
return this._config!.name || ""; | ||
} | ||
|
||
protected render(): TemplateResult { | ||
if (!this.hass || !this._config) { | ||
return html``; | ||
get _icon(): string { | ||
return this._config!.icon || ""; | ||
} | ||
|
||
const entityState = this.hass.states[this._entity]; | ||
protected render(): TemplateResult { | ||
if (!this.hass || !this._config) { | ||
return html``; | ||
} | ||
|
||
return html` | ||
<div class="card-config"> | ||
<ha-entity-picker | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.entity" | ||
)}" | ||
.hass=${this.hass} | ||
.value=${this._entity} | ||
.configValue=${"entity"} | ||
@value-changed=${this._valueChanged} | ||
.includeDomains=${DOMAINS} | ||
allow-custom-entity | ||
></ha-entity-picker> | ||
<div class="side-by-side"> | ||
<paper-input | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.name" | ||
)} (${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.config.optional" | ||
)})" | ||
.value=${this._name} | ||
.configValue=${"name"} | ||
@value-changed=${this._valueChanged} | ||
></paper-input> | ||
<ha-icon-picker | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.icon" | ||
)} (${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.config.optional" | ||
)})" | ||
.value=${this._icon} | ||
.placeholder=${this._icon || stateIcon(entityState)} | ||
.configValue=${"icon"} | ||
@value-changed=${this._valueChanged} | ||
></ha-icon-picker> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
const entityState = this.hass.states[this._entity]; | ||
|
||
private _valueChanged(ev: CustomEvent): void { | ||
if (!this._config || !this.hass) { | ||
return; | ||
return html` | ||
<div class="card-config"> | ||
<ha-entity-picker | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.entity" | ||
)}" | ||
.hass=${this.hass} | ||
.value=${this._entity} | ||
.configValue=${"entity"} | ||
@value-changed=${this._valueChanged} | ||
.includeDomains=${DOMAINS} | ||
allow-custom-entity | ||
></ha-entity-picker> | ||
<div class="side-by-side"> | ||
<paper-input | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.name" | ||
)} (${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.config.optional" | ||
)})" | ||
.value=${this._name} | ||
.configValue=${"name"} | ||
@value-changed=${this._valueChanged} | ||
></paper-input> | ||
<ha-icon-picker | ||
.label="${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.generic.icon" | ||
)} (${this.hass.localize( | ||
"ui.panel.lovelace.editor.card.config.optional" | ||
)})" | ||
.value=${this._icon} | ||
.placeholder=${this._icon || stateIcon(entityState)} | ||
.configValue=${"icon"} | ||
@value-changed=${this._valueChanged} | ||
></ha-icon-picker> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
const target = ev.target! as EditorTarget; | ||
const value = | ||
target.checked !== undefined ? target.checked : ev.detail.value; | ||
|
||
if (this[`_${target.configValue}`] === value) { | ||
return; | ||
} | ||
private _valueChanged(ev: CustomEvent): void { | ||
if (!this._config || !this.hass) { | ||
return; | ||
} | ||
const target = ev.target! as EditorTarget; | ||
const value = | ||
target.checked !== undefined ? target.checked : ev.detail.value; | ||
|
||
if (this[`_${target.configValue}`] === value) { | ||
return; | ||
} | ||
|
||
let newConfig; | ||
if (target.configValue) { | ||
if (!value) { | ||
newConfig = { ...this._config }; | ||
delete newConfig[target.configValue!]; | ||
} else { | ||
newConfig = { | ||
...this._config, | ||
[target.configValue!]: value, | ||
}; | ||
} | ||
let newConfig; | ||
if (target.configValue) { | ||
if (!value) { | ||
newConfig = { ...this._config }; | ||
delete newConfig[target.configValue!]; | ||
} else { | ||
newConfig = { | ||
...this._config, | ||
[target.configValue!]: value, | ||
}; | ||
} | ||
} | ||
fireEvent(this, "config-changed", { config: newConfig }); | ||
} | ||
fireEvent(this, "config-changed", { config: newConfig }); | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return configElementStyle; | ||
} | ||
static get styles(): CSSResultGroup { | ||
return configElementStyle; | ||
} | ||
} |
Oops, something went wrong.