lots of new changes
* HACS badge * hacs.json * New action handling with double tap support * Cleanup
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
LitElement,
|
||||
html,
|
||||
customElement,
|
||||
property,
|
||||
CSSResult,
|
||||
TemplateResult,
|
||||
css,
|
||||
PropertyValues
|
||||
} from "lit-element";
|
||||
import {
|
||||
HomeAssistant,
|
||||
hasConfigOrEntityChanged,
|
||||
hasAction,
|
||||
ActionHandlerEvent,
|
||||
handleAction
|
||||
} from "custom-card-helpers";
|
||||
|
||||
import { BoilerplateConfig } from "./types";
|
||||
import { actionHandler } from "./action-handler-directive";
|
||||
|
||||
// TODO Name your custom element
|
||||
@customElement("boilerplate-card")
|
||||
class BoilerplateCard extends LitElement {
|
||||
// TODO Add any properities that should cause your element to re-render here
|
||||
@property() public hass?: HomeAssistant;
|
||||
@property() private _config?: BoilerplateConfig;
|
||||
|
||||
public setConfig(config: BoilerplateConfig): void {
|
||||
// TODO Check for required fields and that they are of the proper format
|
||||
if (!config || config.show_error) {
|
||||
throw new Error("Invalid configuration");
|
||||
}
|
||||
|
||||
this._config = {
|
||||
name: "Boilerplate",
|
||||
...config
|
||||
};
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
return hasConfigOrEntityChanged(this, changedProps, false);
|
||||
}
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this._config || !this.hass) {
|
||||
return html``;
|
||||
}
|
||||
|
||||
// TODO Check for stateObj or other necessary things and render a warning if missing
|
||||
if (this._config.show_warning) {
|
||||
return html`
|
||||
<ha-card>
|
||||
<div class="warning">Show Warning</div>
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-card
|
||||
.header=${this._config.name}
|
||||
@action=${this._handleAction}
|
||||
.actionHandler=${actionHandler({
|
||||
hasHold: hasAction(this._config!.hold_action),
|
||||
hasDoubleTap: hasAction(this._config!.double_tap_action)
|
||||
})}
|
||||
></ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
private _handleAction(ev: ActionHandlerEvent) {
|
||||
handleAction(this, this.hass!, this._config!, ev.detail.action!);
|
||||
}
|
||||
|
||||
static get styles(): CSSResult {
|
||||
return css`
|
||||
.warning {
|
||||
display: block;
|
||||
color: black;
|
||||
background-color: #fce588;
|
||||
padding: 8px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user