import { HaEntity } from '@/types/types'; import { Lightbulb, Power, Cpu, Lock, Zap, Fan, Cctv, CloudSun } from 'lucide-react-native'; import React from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; const DeviceCard = ({ device, onToggle }: { device: HaEntity; onToggle: (entityId: string) => void; }) => { const getIcon = () => { const domain = device.entity_id.split('.')[0]; switch (domain) { case 'light': return ; case 'switch': return ; case 'sensor': return ; case 'lock': return ; case 'fan': return ; case 'camera': return ; case 'weather': return ; default: return ; } }; const isToggleable = ['light', 'switch', 'fan', 'input_boolean'].includes(device.entity_id.split('.')[0]); const isOn = device.state === 'on'; const getDeviceState = (state: string) => { switch (state) { case 'on': return 'Acceso'; case 'off': return 'Spento'; case 'idle': return 'Inattivo'; case 'locked': return 'Bloccato'; case 'unlocked': return 'Sbloccato'; case 'unavailable': return 'Non disponibile'; case 'unknown': return 'Sconosciuto'; default: return state; } } return ( {getIcon()} {isToggleable && ( onToggle(device.entity_id)} className={`w-12 h-7 rounded-full p-1 ${isOn ? 'bg-[#099499]' : 'bg-gray-200'} active:scale-[0.9]`} > )} {device.name} {getDeviceState(device.state)} ); }; export default DeviceCard;