From fde0d6126fb608a8b3ee98fd38c27a2f1c9bb4df Mon Sep 17 00:00:00 2001 From: Bram van Dartel Date: Mon, 11 Oct 2021 07:56:40 +0200 Subject: [PATCH] fix config flow --- custom_components/afvalwijzer/config_flow.py | 81 ------------------- custom_components/afvalwijzer/manifest.json | 2 +- custom_components/afvalwijzer/sensor.py | 2 +- .../afvalwijzer/translations/en.json | 23 ------ 4 files changed, 2 insertions(+), 106 deletions(-) delete mode 100644 custom_components/afvalwijzer/config_flow.py delete mode 100644 custom_components/afvalwijzer/translations/en.json diff --git a/custom_components/afvalwijzer/config_flow.py b/custom_components/afvalwijzer/config_flow.py deleted file mode 100644 index 1a78906..0000000 --- a/custom_components/afvalwijzer/config_flow.py +++ /dev/null @@ -1,81 +0,0 @@ -"""Config flow to configure the AfvalWijzer integration.""" -from __future__ import annotations - -from typing import Any - -import voluptuous as vol -from homeassistant.config_entries import ConfigFlow -from homeassistant.const import CONF_ID -from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.aiohttp_client import async_get_clientsession - -from ..const.const import ( - CONF_DEFAULT_LABEL, - CONF_EXCLUDE_LIST, - CONF_ID, - CONF_INCLUDE_DATE_TODAY, - CONF_POSTAL_CODE, - CONF_PROVIDER, - CONF_STREET_NUMBER, - CONF_SUFFIX, - DOMAIN, -) -from .provider.afvalwijzer import AfvalWijzer - - -class AfvalWijzerFlowHandler(ConfigFlow, domain=DOMAIN): - """Handle AfvalWijzer config flow.""" - - VERSION = 1 - - async def _show_setup_form( - self, errors: dict[str, str] | None = None - ) -> FlowResult: - """Show the setup form to the user.""" - return self.async_show_form( - step_id="user", - data_schema=vol.Schema( - { - vol.Required(CONF_PROVIDER): str, - vol.Required(CONF_POSTAL_CODE): str, - vol.Required(CONF_STREET_NUMBER): str, - vol.Optional(CONF_SUFFIX): str, - } - ), - errors=errors or {}, - ) - - async def async_step_user( - self, user_input: dict[str, Any] | None = None - ) -> FlowResult: - """Handle a flow initiated by the user.""" - if user_input is None: - return await self._show_setup_form(user_input) - - session = async_get_clientsession(self.hass) - - afvalwijzer = AfvalWijzer( - provider=user_input[CONF_PROVIDER], - postal_code=user_input[CONF_POSTAL_CODE], - street_number=user_input[CONF_STREET_NUMBER], - suffix=user_input.get(CONF_SUFFIX), - include_date_today=CONF_INCLUDE_DATE_TODAY, - default_label=CONF_DEFAULT_LABEL, - exclude_list=CONF_EXCLUDE_LIST, - session=session, - ) - - try: - await afvalwijzer.waste_data_without_today() - except Exception as err: - return await self._show_setup_form(err) - - return self.async_create_entry( - title=str(CONF_ID), - data={ - CONF_PROVIDER: user_input[CONF_PROVIDER], - CONF_POSTAL_CODE: user_input[CONF_POSTAL_CODE], - CONF_STREET_NUMBER: user_input[CONF_STREET_NUMBER], - CONF_SUFFIX: user_input.get(CONF_SUFFIX), - }, - ) diff --git a/custom_components/afvalwijzer/manifest.json b/custom_components/afvalwijzer/manifest.json index 0a8f191..6737042 100644 --- a/custom_components/afvalwijzer/manifest.json +++ b/custom_components/afvalwijzer/manifest.json @@ -11,4 +11,4 @@ "@xirixiz" ], "requirements": [] -} \ No newline at end of file +} diff --git a/custom_components/afvalwijzer/sensor.py b/custom_components/afvalwijzer/sensor.py index 9703c3f..a158150 100755 --- a/custom_components/afvalwijzer/sensor.py +++ b/custom_components/afvalwijzer/sensor.py @@ -17,12 +17,12 @@ from .const.const import ( _LOGGER, CONF_DEFAULT_LABEL, - CONF_EXCLUDE_LIST, CONF_ID, CONF_INCLUDE_DATE_TODAY, CONF_POSTAL_CODE, CONF_PROVIDER, CONF_STREET_NUMBER, + CONF_EXCLUDE_LIST, CONF_SUFFIX, MIN_TIME_BETWEEN_UPDATES, PARALLEL_UPDATES, diff --git a/custom_components/afvalwijzer/translations/en.json b/custom_components/afvalwijzer/translations/en.json deleted file mode 100644 index e275bc7..0000000 --- a/custom_components/afvalwijzer/translations/en.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "config": { - "abort": { - "already_configured": "Location is already configured" - }, - "error": { - "cannot_connect": "Failed to connect", - "invalid_address": "Address not found in Afvalwijzer service area." - }, - "step": { - "user": { - "data": { - "provider": "Waste provider", - "street_number": "House number", - "suffox": "House letter/additional", - "postal_code": "Postal code" - }, - "description": "Set up Afvalwijzer providing waste collection information on your address.", - "title": "Afvalwijzer" - } - } - } -}