From dfd77b392a6d792ff3164c350176dc9279415c0f Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Thu, 20 Mar 2025 21:35:09 +0100 Subject: [PATCH] feat: add Home Assistant example Plugin --- database/seeders/ExampleReceiptsSeeder.php | 19 ++++++ .../views/flux/icon/thermometer.blade.php | 41 +++++++++++ .../views/receipts/home-assistant.blade.php | 68 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 resources/views/flux/icon/thermometer.blade.php create mode 100644 resources/views/receipts/home-assistant.blade.php diff --git a/database/seeders/ExampleReceiptsSeeder.php b/database/seeders/ExampleReceiptsSeeder.php index d1f1b8c..9f3971e 100644 --- a/database/seeders/ExampleReceiptsSeeder.php +++ b/database/seeders/ExampleReceiptsSeeder.php @@ -87,5 +87,24 @@ class ExampleReceiptsSeeder extends Seeder 'flux_icon_name' => 'calendar', ] ); + + Plugin::create( + [ + 'uuid' => '4349fdad-a273-450b-aa00-3d32f2de788d', + 'name' => 'Home Assistant', + 'user_id' => '1', + 'data_payload' => null, + 'data_stale_minutes' => 30, + 'data_strategy' => 'polling', + 'polling_url' => 'http://raspberrypi.local:8123/api/states', + 'polling_verb' => 'get', + 'polling_header' => 'Authorization: Bearer YOUR_API_KEY', + 'render_markup' => null, + 'render_markup_view' => 'receipts.home-assistant', + 'detail_view_route' => null, + 'icon_url' => null, + 'flux_icon_name' => 'thermometer', + ] + ); } } diff --git a/resources/views/flux/icon/thermometer.blade.php b/resources/views/flux/icon/thermometer.blade.php new file mode 100644 index 0000000..decfe4f --- /dev/null +++ b/resources/views/flux/icon/thermometer.blade.php @@ -0,0 +1,41 @@ +{{-- Credit: Lucide (https://lucide.dev) --}} + +@props([ + 'variant' => 'outline', +]) + +@php +if ($variant === 'solid') { + throw new \Exception('The "solid" variant is not supported in Lucide.'); +} + +$classes = Flux::classes('shrink-0') + ->add(match($variant) { + 'outline' => '[:where(&)]:size-6', + 'solid' => '[:where(&)]:size-6', + 'mini' => '[:where(&)]:size-5', + 'micro' => '[:where(&)]:size-4', + }); + +$strokeWidth = match ($variant) { + 'outline' => 2, + 'mini' => 2.25, + 'micro' => 2.5, +}; +@endphp + +class($classes) }} + data-flux-icon + xmlns="http://www.w3.org/2000/svg" + viewBox="0 0 24 24" + fill="none" + stroke="currentColor" + stroke-width="{{ $strokeWidth }}" + stroke-linecap="round" + stroke-linejoin="round" + aria-hidden="true" + data-slot="icon" +> + + diff --git a/resources/views/receipts/home-assistant.blade.php b/resources/views/receipts/home-assistant.blade.php new file mode 100644 index 0000000..f5e20d5 --- /dev/null +++ b/resources/views/receipts/home-assistant.blade.php @@ -0,0 +1,68 @@ +@php + $weatherEntity = collect($data)->first(function($entity) { + return $entity['entity_id'] === 'weather.forecast_home'; + }); +@endphp + + + + @if($weatherEntity) + +
+
+ +
+
+
+
+
+ {{ $weatherEntity['attributes']['temperature'] }} + Temperature {{ $weatherEntity['attributes']['temperature_unit'] }} +
+
+
+
+
+
+
+ {{-- --}} +
+
+ {{ $weatherEntity['attributes']['wind_speed'] }} {{ $weatherEntity['attributes']['wind_speed_unit'] }} + Wind Speed +
+
+ +
+
+
+ {{-- --}} +
+
+ {{ $weatherEntity['attributes']['humidity'] }}% + Humidity +
+
+ +
+
+
+ {{-- --}} +
+
+ {{ Str::title($weatherEntity['state']) }} + Right Now +
+
+
+
+ + @else +

Weather forecast data not found.

+ @endif +
+ + +