custom-card-helpers
Version:
Set of helpful functions and types for Custom Card creators
27 lines (24 loc) • 629 B
text/typescript
import { PropertyValues } from "lit";
import { HomeAssistant } from "./types";
// Check if config or Entity changed
export function hasConfigOrEntityChanged(
element: any,
changedProps: PropertyValues,
forceUpdate: Boolean,
): boolean {
if (changedProps.has('config') || forceUpdate) {
return true;
}
if (element.config!.entity) {
const oldHass = changedProps.get('hass') as HomeAssistant | undefined;
if (oldHass) {
return (
oldHass.states[element.config!.entity]
!== element.hass!.states[element.config!.entity]
);
}
return true;
} else {
return false;
}
}