From 62782f744c4971080dcfb34a342bae970f8073f9 Mon Sep 17 00:00:00 2001
From: paulfantom <pawel@krupa.net.pl>
Date: Mon, 16 Oct 2023 19:23:20 +0200
Subject: [PATCH] apps/homeassistant: add tomorrow meals and remove todays

---
 apps/homeassistant/config/configuration.yaml  | 56 +++++++++++++++----
 .../manifests/homeassistant/configs.yaml      | 56 +++++++++++++++----
 .../manifests/homeassistant/statefulSet.yaml  |  2 +-
 3 files changed, 93 insertions(+), 21 deletions(-)

diff --git a/apps/homeassistant/config/configuration.yaml b/apps/homeassistant/config/configuration.yaml
index e87435e92..4b74e539e 100644
--- a/apps/homeassistant/config/configuration.yaml
+++ b/apps/homeassistant/config/configuration.yaml
@@ -201,6 +201,42 @@ sensor:
       {% endif %}
 
 rest:
+#  - resource: https://recipes.krupa.net.pl/api/meal-plan
+#    scan_interval: 3600
+#    headers:
+#      content-type: application/json
+#      authorization: !secret recipes_token
+#    params:
+#      from_date: >
+#        {{ now().strftime("%Y-%m-%d") }}
+#      to_date: >
+#        {{ now().strftime("%Y-%m-%d") }}
+#    sensor:
+#      - name: "Today's Breakfast"
+#        unique_id: "meal_today_breakfast"
+#        value_template: >
+#          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Breakfast') | first -%}
+#          {{ data.title if data.title else data.recipe_name | default() }}
+#      - name: "Today's Lunch"
+#        unique_id: "meal_today_lunch"
+#        value_template: >
+#          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Lunch') | first -%}
+#          {{ data.title if data.title else data.recipe_name | default() }}
+#      - name: "Today's Snack"
+#        unique_id: "meal_today_snack"
+#        value_template: >
+#          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Snack') | first -%}
+#          {{ data.title if data.title else data.recipe_name | default() }}
+#      - name: "Today's Dinner"
+#        unique_id: "meal_today_dinner"
+#        value_template: >
+#          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Dinner') | first -%}
+#          {{ data.title if data.title else data.recipe_name | default() }}
+#        json_attributes_path: "$.[?(@.meal_type_name=='Dinnert')].recipe"
+#        json_attributes:
+#          - image
+#          - id
+#          - name
   - resource: https://recipes.krupa.net.pl/api/meal-plan
     scan_interval: 3600
     headers:
@@ -208,27 +244,27 @@ rest:
       authorization: !secret recipes_token
     params:
       from_date: >
-        {{ now().strftime("%Y-%m-%d") }}
+        {{ (now().date() + timedelta(days=1)).strftime("%Y-%m-%d") }}
       to_date: >
-        {{ now().strftime("%Y-%m-%d") }}
+        {{ (now().date() + timedelta(days=1)).strftime("%Y-%m-%d") }}
     sensor:
-      - name: "Today's Breakfast"
-        unique_id: "meal_today_breakfast"
+      - name: "Tomorrow's Breakfast"
+        unique_id: "meal_tomorrow_breakfast"
         value_template: >
           {% set data = value_json | selectattr('meal_type_name', 'eq', 'Breakfast') | first -%}
           {{ data.title if data.title else data.recipe_name | default() }}
-      - name: "Today's Lunch"
-        unique_id: "meal_today_lunch"
+      - name: "Tomorrow's Lunch"
+        unique_id: "meal_tomorrow_lunch"
         value_template: >
           {% set data = value_json | selectattr('meal_type_name', 'eq', 'Lunch') | first -%}
           {{ data.title if data.title else data.recipe_name | default() }}
-      - name: "Today's Snack"
-        unique_id: "meal_today_snack"
+      - name: "Tomorrow's Snack"
+        unique_id: "meal_tomorrow_snack"
         value_template: >
           {% set data = value_json | selectattr('meal_type_name', 'eq', 'Snack') | first -%}
           {{ data.title if data.title else data.recipe_name | default() }}
-      - name: "Today's Dinner"
-        unique_id: "meal_today_dinner"
+      - name: "Tomorrow's Dinner"
+        unique_id: "meal_tomorrow_dinner"
         value_template: >
           {% set data = value_json | selectattr('meal_type_name', 'eq', 'Dinner') | first -%}
           {{ data.title if data.title else data.recipe_name | default() }}
diff --git a/apps/homeassistant/manifests/homeassistant/configs.yaml b/apps/homeassistant/manifests/homeassistant/configs.yaml
index eede73073..3c802950e 100644
--- a/apps/homeassistant/manifests/homeassistant/configs.yaml
+++ b/apps/homeassistant/manifests/homeassistant/configs.yaml
@@ -204,6 +204,42 @@ data:
           {% endif %}
 
     rest:
+    #  - resource: https://recipes.krupa.net.pl/api/meal-plan
+    #    scan_interval: 3600
+    #    headers:
+    #      content-type: application/json
+    #      authorization: !secret recipes_token
+    #    params:
+    #      from_date: >
+    #        {{ now().strftime("%Y-%m-%d") }}
+    #      to_date: >
+    #        {{ now().strftime("%Y-%m-%d") }}
+    #    sensor:
+    #      - name: "Today's Breakfast"
+    #        unique_id: "meal_today_breakfast"
+    #        value_template: >
+    #          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Breakfast') | first -%}
+    #          {{ data.title if data.title else data.recipe_name | default() }}
+    #      - name: "Today's Lunch"
+    #        unique_id: "meal_today_lunch"
+    #        value_template: >
+    #          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Lunch') | first -%}
+    #          {{ data.title if data.title else data.recipe_name | default() }}
+    #      - name: "Today's Snack"
+    #        unique_id: "meal_today_snack"
+    #        value_template: >
+    #          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Snack') | first -%}
+    #          {{ data.title if data.title else data.recipe_name | default() }}
+    #      - name: "Today's Dinner"
+    #        unique_id: "meal_today_dinner"
+    #        value_template: >
+    #          {% set data = value_json | selectattr('meal_type_name', 'eq', 'Dinner') | first -%}
+    #          {{ data.title if data.title else data.recipe_name | default() }}
+    #        json_attributes_path: "$.[?(@.meal_type_name=='Dinnert')].recipe"
+    #        json_attributes:
+    #          - image
+    #          - id
+    #          - name
       - resource: https://recipes.krupa.net.pl/api/meal-plan
         scan_interval: 3600
         headers:
@@ -211,27 +247,27 @@ data:
           authorization: !secret recipes_token
         params:
           from_date: >
-            {{ now().strftime("%Y-%m-%d") }}
+            {{ (now().date() + timedelta(days=1)).strftime("%Y-%m-%d") }}
           to_date: >
-            {{ now().strftime("%Y-%m-%d") }}
+            {{ (now().date() + timedelta(days=1)).strftime("%Y-%m-%d") }}
         sensor:
-          - name: "Today's Breakfast"
-            unique_id: "meal_today_breakfast"
+          - name: "Tomorrow's Breakfast"
+            unique_id: "meal_tomorrow_breakfast"
             value_template: >
               {% set data = value_json | selectattr('meal_type_name', 'eq', 'Breakfast') | first -%}
               {{ data.title if data.title else data.recipe_name | default() }}
-          - name: "Today's Lunch"
-            unique_id: "meal_today_lunch"
+          - name: "Tomorrow's Lunch"
+            unique_id: "meal_tomorrow_lunch"
             value_template: >
               {% set data = value_json | selectattr('meal_type_name', 'eq', 'Lunch') | first -%}
               {{ data.title if data.title else data.recipe_name | default() }}
-          - name: "Today's Snack"
-            unique_id: "meal_today_snack"
+          - name: "Tomorrow's Snack"
+            unique_id: "meal_tomorrow_snack"
             value_template: >
               {% set data = value_json | selectattr('meal_type_name', 'eq', 'Snack') | first -%}
               {{ data.title if data.title else data.recipe_name | default() }}
-          - name: "Today's Dinner"
-            unique_id: "meal_today_dinner"
+          - name: "Tomorrow's Dinner"
+            unique_id: "meal_tomorrow_dinner"
             value_template: >
               {% set data = value_json | selectattr('meal_type_name', 'eq', 'Dinner') | first -%}
               {{ data.title if data.title else data.recipe_name | default() }}
diff --git a/apps/homeassistant/manifests/homeassistant/statefulSet.yaml b/apps/homeassistant/manifests/homeassistant/statefulSet.yaml
index 9cd9f972a..95ff58263 100644
--- a/apps/homeassistant/manifests/homeassistant/statefulSet.yaml
+++ b/apps/homeassistant/manifests/homeassistant/statefulSet.yaml
@@ -19,7 +19,7 @@ spec:
   template:
     metadata:
       annotations:
-        checksum.config/md5: 04e3e5c08a9eaa39e8c97afc9f17c7af
+        checksum.config/md5: 1e20742629d2ff25dec30a78f9fe1e60
       labels:
         app.kubernetes.io/component: server
         app.kubernetes.io/name: homeassistant