From 162a2b79ca0722f1504d2d91bae0b0b1e273e93b Mon Sep 17 00:00:00 2001 From: dmyoung9 Date: Tue, 12 Jul 2022 16:41:41 -0700 Subject: [PATCH] :sparkles: - Add Mealie URL as sensor attribute --- custom_components/mealie/__init__.py | 1 + custom_components/mealie/api.py | 3 +++ custom_components/mealie/sensor.py | 1 + 3 files changed, 5 insertions(+) diff --git a/custom_components/mealie/__init__.py b/custom_components/mealie/__init__.py index 04dac1b..cf456e5 100644 --- a/custom_components/mealie/__init__.py +++ b/custom_components/mealie/__init__.py @@ -102,6 +102,7 @@ async def _async_update_data(self): try: data = {} + data['host'] = self.api.get_host() data['app/about'] = await self.api.async_get_api_app_about() data[ 'groups/mealplans/today' diff --git a/custom_components/mealie/api.py b/custom_components/mealie/api.py index 8489716..74c3a91 100644 --- a/custom_components/mealie/api.py +++ b/custom_components/mealie/api.py @@ -72,6 +72,9 @@ def __init__( "Accept": "application/json", } + def get_host(self): + return self._host + @apirequest async def _get( self, diff --git a/custom_components/mealie/sensor.py b/custom_components/mealie/sensor.py index bd4e77b..baae456 100644 --- a/custom_components/mealie/sensor.py +++ b/custom_components/mealie/sensor.py @@ -140,6 +140,7 @@ def extra_state_attributes(self): "description": recipe.get("description"), "name": recipe.get("name"), "original_url": recipe.get("orgURL"), + "mealie_url": f"{self.coordinator.data.get('host', '')}/recipe/{recipe.get('slug', '')}", "assets": clean_obj(recipe.get("assets", [])), "notes": clean_obj(recipe.get("notes", [])), "extras": clean_obj(recipe.get("extras", {})),