From ae5a4d2070a381642ce7d4bd621d92dd51a6e0f4 Mon Sep 17 00:00:00 2001 From: Roeland Date: Wed, 11 Sep 2024 14:50:34 +0200 Subject: [PATCH] add translations for service --- custom_components/entsoe/coordinator.py | 4 +- custom_components/entsoe/services.py | 2 +- custom_components/entsoe/translations/en.json | 46 +++++++++++++------ custom_components/entsoe/translations/nl.json | 20 ++++++++ 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/custom_components/entsoe/coordinator.py b/custom_components/entsoe/coordinator.py index 6b13da0..c48ce9b 100644 --- a/custom_components/entsoe/coordinator.py +++ b/custom_components/entsoe/coordinator.py @@ -121,7 +121,7 @@ def check_update_needed(self, now): return True if len(self.get_data_today()) != 24: return True - if len(self.get_data_tomorrow()) != 24 and now.hour > 12: + if len(self.get_data_tomorrow()) != 24 and now.hour > 11: return True return False @@ -167,7 +167,7 @@ async def get_energy_prices(self, start_date, end_date): for k, v in self.data.items() if k.date() >= start_date.date() and k.date() <= end_date.date() } - return await self.fetch_prices(start_date, end_date) + return self.parse_hourprices(await self.fetch_prices(start_date, end_date)) def today_data_available(self): return len(self.get_data_today()) == 24 diff --git a/custom_components/entsoe/services.py b/custom_components/entsoe/services.py index 369204e..907f464 100644 --- a/custom_components/entsoe/services.py +++ b/custom_components/entsoe/services.py @@ -46,7 +46,7 @@ def __get_date(date_input: str | None) -> date | datetime: """Get date.""" if not date_input: - return dt_util.now().date() + return dt_util.now() if value := dt_util.parse_datetime(date_input): return value diff --git a/custom_components/entsoe/translations/en.json b/custom_components/entsoe/translations/en.json index 849a6a6..985b9a3 100644 --- a/custom_components/entsoe/translations/en.json +++ b/custom_components/entsoe/translations/en.json @@ -2,18 +2,18 @@ "config": { "step": { "user": { - "description": "Please add the ENTSO-e Transparency Platform API key and area", - "data": { - "api_key": "Your API Key", - "area": "Area*", - "advanced_options": "I want to set VAT, template and calculation method (next step)", - "modifyer": "Price Modifyer Template (Optional)", - "currency": "Currency of the modified price (Optional)", - "name": "Name (Optional)" - } + "description": "Please add the ENTSO-e Transparency Platform API key and area", + "data": { + "api_key": "Your API Key", + "area": "Area*", + "advanced_options": "I want to set VAT, template and calculation method (next step)", + "modifyer": "Price Modifyer Template (Optional)", + "currency": "Currency of the modified price (Optional)", + "name": "Name (Optional)" + } }, "extra": { - "data":{ + "data": { "VAT_value": "VAT tariff", "modifyer": "Price Modifyer Template (Optional)", "currency": "Currency of the modified price (Optional)" @@ -24,7 +24,7 @@ "invalid_template": "Invalid template, check https://github.com/JaccoR/hass-entso-e", "missing_current_price": "'current_price' is missing from the template, check https://github.com/JaccoR/hass-entso-e", "already_configured": "Integration instance with the same name already exists" - } + } }, "options": { "step": { @@ -44,6 +44,26 @@ "invalid_template": "Invalid Template, Check https://github.com/JaccoR/hass-entso-e", "missing_current_price": "'current_price' is missing from the template, check https://github.com/JaccoR/hass-entso-e", "already_configured": "Integration instance with the same name already exists" + } + }, + "services": { + "get_energy_prices": { + "name": "Get energy prices", + "description": "Request prices for a specified range from entso-e", + "fields": { + "config_entry": { + "name": "Config Entry", + "description": "The config entry to use for this service." + }, + "start": { + "name": "Start", + "description": "Specifies the date and time from which to retrieve prices. Defaults to today if omitted." + }, + "end": { + "name": "End", + "description": "Specifies the date and time until which to retrieve prices. Defaults to today if omitted." + } + } + } } - } -} +} \ No newline at end of file diff --git a/custom_components/entsoe/translations/nl.json b/custom_components/entsoe/translations/nl.json index dfe1cbb..4d48511 100644 --- a/custom_components/entsoe/translations/nl.json +++ b/custom_components/entsoe/translations/nl.json @@ -34,5 +34,25 @@ "missing_current_price": "'current_price' is missing from the template", "already_configured": "Integration instance with the same name already exists" } + }, + "services": { + "get_energy_prices": { + "name": "Get energy prices", + "description": "Request prices for a specified range from entso-e", + "fields": { + "config_entry": { + "name": "Config Entry", + "description": "The config entry to use for this service." + }, + "start": { + "name": "Start", + "description": "Specifies the date and time from which to retrieve prices. Defaults to today if omitted." + }, + "end": { + "name": "End", + "description": "Specifies the date and time until which to retrieve prices. Defaults to today if omitted." + } + } + } } } \ No newline at end of file