Autodetect motion and occupancy sensors.

This commit is contained in:
Dermot Duffy
2022-05-21 11:23:31 -07:00
parent 4a40e4a943
commit c8d9e89b78
10 changed files with 358 additions and 80 deletions
+18 -2
View File
@@ -4,8 +4,7 @@ import { StyleInfo } from 'lit/directives/style-map.js';
import { ZodSchema } from 'zod';
import { localize } from '../../localize/localize.js';
import {
CardHelpers,
ExtendedHomeAssistant,
CardHelpers, ExtendedHomeAssistant,
SignedPath,
signedPathSchema,
StateParameters
@@ -306,3 +305,20 @@ export const sideLoadHomeAssistantElements = async (): Promise<boolean> => {
export const isTriggeredState = (state?: HassEntity): boolean => {
return !!state && ['on', 'open'].includes(state.state);
};
/**
* Get entities from the HASS object.
* @param hass
* @param domain
* @returns
*/
export const getEntitiesFromHASS = (hass: HomeAssistant, domain?: string): string[] => {
if (!hass) {
return [];
}
const entities = Object.keys(hass.states).filter(
(eid) => !domain || eid.substr(0, eid.indexOf('.')) === domain,
);
entities.sort();
return entities;
}