UNPKG

matterbridge-hass

Version:
30 lines (29 loc) 1.64 kB
import { genericSwitch } from 'matterbridge'; import { CYAN, db, debugStringify } from 'matterbridge/logger'; import { Switch } from 'matterbridge/matter/clusters'; import { isValidString } from 'matterbridge/utils'; import { hassDomainEventConverter } from './converters.js'; import { getDomain } from './helpers.js'; export function addEventEntity(platform, mutableDevice, entity, state) { const endpointName = entity.entity_id; const domain = getDomain(entity.entity_id); const supportedEventTypes = []; if (domain !== 'event') return undefined; platform.log.debug(`- domain ${domain} deviceClass ${state.attributes.device_class} endpoint '${CYAN}${endpointName}${db}' for entity ${CYAN}${entity.entity_id}${db}`); for (const eventType of state.attributes.event_types || []) { if (hassDomainEventConverter.find((e) => e.hassEventType === eventType)) { platform.log.debug(`+ event ${CYAN}${eventType}${db}`); supportedEventTypes.push(eventType); } } if (supportedEventTypes.length === 0) return undefined; platform.log.debug(`+ domain event supported [${supportedEventTypes.join(', ')}] device ${CYAN}${genericSwitch.name}${db} cluster ${CYAN}${Switch.Cluster.name}${db}`); mutableDevice.addDeviceTypes(endpointName, genericSwitch); mutableDevice.addClusterServerIds(endpointName, Switch.Cluster.id); if (isValidString(state.attributes['friendly_name'])) mutableDevice.setFriendlyName(endpointName, state.attributes['friendly_name']); platform.log.debug(`- state ${debugStringify(state)}`); return endpointName; }