homeos/resources/views/components/entity-state.blade.php

53 lines
1.9 KiB
PHP

@props(['entity'])
@php
$s = $entity->state?->state ?? [];
@endphp
@switch($entity->type)
@case('light')
@case('switch')
@php $on = ($s['on'] ?? false) === true; @endphp
<x-status-pill :state="$on ? 'online' : 'neutral'">
{{ $entity->name }} · {{ $on ? __('devices.on') : __('devices.off') }}
</x-status-pill>
@break
@case('contact')
@php
$pos = $s['position'] ?? (($s['open'] ?? false) === true ? 'open' : 'closed');
$pillState = match ($pos) { 'open' => 'offline', 'tilted' => 'warning', default => 'neutral' };
@endphp
<x-status-pill :state="$pillState">
{{ $entity->name }} · {{ __('devices.contact_'.$pos) }}
</x-status-pill>
@break
@case('battery')
@php $p = (int) ($s['percent'] ?? 0); $low = $p < 20; @endphp
<x-status-pill :state="$low ? 'offline' : 'neutral'">
{{ __('devices.battery') }} · <span class="font-mono tabular-nums">{{ $p }}%</span>
</x-status-pill>
@break
@case('power')
<span class="inline-flex items-center gap-1.5 rounded-full bg-inset px-2.5 py-[3px] text-[10.5px] font-bold text-ink-2">
<span class="font-mono tabular-nums">{{ (int) ($s['watts'] ?? 0) }} W</span>
</span>
@break
@case('motion')
@php $active = ($s['on'] ?? $s['active'] ?? false) === true; @endphp
<x-status-pill :state="$active ? 'warning' : 'neutral'">
{{ $active ? __('devices.motion') : __('devices.no_motion') }}
</x-status-pill>
@break
@case('input')
@php $on = ($s['on'] ?? false) === true; @endphp
<x-status-pill :state="$on ? 'online' : 'neutral'">
{{ $entity->name ?: __('devices.input') }} · {{ $on ? __('devices.on') : __('devices.off') }}
</x-status-pill>
@break
@endswitch