From a8ed930477ed969100a92e7ff50d3acf6559c1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 15 Mar 2020 11:57:07 +0100 Subject: [PATCH] Add coronavirus_hessen.refresh service Allows manual refresh of the data from the web. --- custom_components/coronavirus_hessen/__init__.py | 9 ++++++++- custom_components/coronavirus_hessen/services.yaml | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 custom_components/coronavirus_hessen/services.yaml diff --git a/custom_components/coronavirus_hessen/__init__.py b/custom_components/coronavirus_hessen/__init__.py index 4dc23a5..cbe26d9 100644 --- a/custom_components/coronavirus_hessen/__init__.py +++ b/custom_components/coronavirus_hessen/__init__.py @@ -22,7 +22,14 @@ async def async_setup(hass: HomeAssistant, config: dict): """Set up the Coronavirus Hessen component.""" # Make sure coordinator is initialized. - await get_coordinator(hass) + coordinator = await get_coordinator(hass) + + async def handle_refresh(call): + _LOGGER.info("Refreshing Coronavirus Hessen data...") + await coordinator.async_refresh() + + hass.services.async_register(DOMAIN, "refresh", handle_refresh) + return True diff --git a/custom_components/coronavirus_hessen/services.yaml b/custom_components/coronavirus_hessen/services.yaml new file mode 100644 index 0000000..6cbf21c --- /dev/null +++ b/custom_components/coronavirus_hessen/services.yaml @@ -0,0 +1,2 @@ +refresh: + description: Refreshes the data from the web