import type { IBlocksNode, IEventBus, IFullBlocksClient, ISerialisable, } from '@hass-blocks/core'; import { useEffect, useState } from 'react'; import { Automation } from '../automation/automation.tsx'; import type { LifeCycleEvent } from '@types'; import { Box } from 'ink'; interface AutomationListProps { hass: IFullBlocksClient; bus: IEventBus; } export const AutomationList = ({ hass, bus }: AutomationListProps) => { const [events, setEvents] = useState([]); const [automations, setAutomations] = useState< (IBlocksNode & ISerialisable)[] >([]); useEffect(() => { bus.subscribe((event) => { if ( event.eventType === 'block-started' || event.eventType === 'block-finished' || event.eventType === 'block-failed' || event.eventType === 'sequence-aborted' ) { setEvents((events) => [...events, event]); } }); }, []); // biome-ignore lint/correctness/useExhaustiveDependencies: useEffect(() => { bus.subscribe((event) => { if (event.eventType === 'automation-registered') { const newAutomations = hass.getAutomations(); setAutomations(newAutomations); } }); }, []); return ( {automations.map((automation) => ( 'parent' in event ? event.parent.id === automation.id : event.block.id === automation.id, )} /> ))} ); };