import { useMemo } from 'react'; import { useSession } from '../context/SessionContext.jsx'; import { useControlSystem } from '../controls/index.js'; import { formatKeyLabel } from '../controls/keymapUtils.js'; function StatusBadge({ label, tone = 'muted' }) { const styles = tone === 'success' ? 'bg-emerald-900 text-emerald-100' : tone === 'warn' ? 'bg-amber-900 text-amber-100' : 'bg-slate-800 text-slate-200'; return ( {label} ); } function EntityRow({ entity, connected, onToggle }) { const unavailable = entity.state === 'unavailable' || !entity.available; const isOn = entity.state === 'on'; const statusTone = unavailable ? 'warn' : isOn ? 'success' : 'muted'; const statusLabel = unavailable ? 'Unavailable' : isOn ? 'On' : 'Off'; const disableToggle = !connected || unavailable; const toneStyles = unavailable ? 'border-slate-800 bg-slate-900 text-slate-400 cursor-not-allowed' : isOn ? 'border-emerald-700 bg-emerald-900/80 text-emerald-50 hover:bg-emerald-800' : 'border-rose-800 bg-rose-900/80 text-rose-50 hover:bg-rose-800'; return ( ); } export default function HomeAssistantControls() { const { state: { keymap }, } = useControlSystem(); const { session, homeAssistantToggle } = useSession(); const ha = session?.homeAssistant; const entities = useMemo(() => ha?.entities || [], [ha?.entities]); const onKeyLabel = formatKeyLabel(keymap?.homeAssistantOn?.[0]); const offKeyLabel = formatKeyLabel(keymap?.homeAssistantOff?.[0]); if (!ha?.enabled) { return (

Light Controls

Not configured on the server.

); } if (entities.length === 0) { return (

Light Controls

No lights or switches configured.

); } const connected = Boolean(ha?.connected); return (

Light Controls

{entities.length}
On {onKeyLabel ? : null} Off {offKeyLabel ? : null}
{entities.map((entity) => ( ))}
); } function KeyPill({ label }) { if (!label) return null; return {label}; }