From a727e061d6c04e1ef335dc8c0569464d49b7d2d1 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Mon, 20 Apr 2020 17:54:58 +0000 Subject: [PATCH] Show how to only allow one instance --- .devcontainer/devcontainer.json | 2 +- .../blueprint/.translations/en.json | 3 +++ .../blueprint/.translations/nb.json | 3 +++ custom_components/blueprint/config_flow.py | 22 +++++++++++-------- custom_components/blueprint/entity.py | 8 +++---- hacs.json | 10 +++++++-- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 46a77f9..ae64d87 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ "appPort": [ "9123:8123" ], - "postCreateCommand": "dc install", + "postCreateCommand": "cc install", "runArgs": [ "-v", "${env:HOME}${env:USERPROFILE}/.ssh:/tmp/.ssh" diff --git a/custom_components/blueprint/.translations/en.json b/custom_components/blueprint/.translations/en.json index a266873..300e60c 100644 --- a/custom_components/blueprint/.translations/en.json +++ b/custom_components/blueprint/.translations/en.json @@ -13,6 +13,9 @@ }, "error": { "auth": "Username/Password is wrong." + }, + "abort": { + "single_instance_allowed": "Only a single configuration of Blueprint is allowed." } }, "options": { diff --git a/custom_components/blueprint/.translations/nb.json b/custom_components/blueprint/.translations/nb.json index 6151e02..c53e807 100644 --- a/custom_components/blueprint/.translations/nb.json +++ b/custom_components/blueprint/.translations/nb.json @@ -13,6 +13,9 @@ }, "error": { "auth": "Brukernavn/Passord er feil." + }, + "abort": { + "single_instance_allowed": "Du kan konfigurere Blueprint kun en gang." } }, "options": { diff --git a/custom_components/blueprint/config_flow.py b/custom_components/blueprint/config_flow.py index 567e351..b030ed6 100644 --- a/custom_components/blueprint/config_flow.py +++ b/custom_components/blueprint/config_flow.py @@ -1,15 +1,14 @@ """Adds config flow for Blueprint.""" -from collections import OrderedDict - import voluptuous as vol -from sampleclient.client import Client from homeassistant import config_entries from homeassistant.core import callback -from custom_components.blueprint.const import ( - DOMAIN, +from sampleclient.client import Client + +from custom_components.blueprint.const import ( # pylint: disable=unused-import CONF_PASSWORD, CONF_USERNAME, + DOMAIN, PLATFORMS, ) @@ -25,10 +24,15 @@ def __init__(self): self._errors = {} async def async_step_user( - self, user_input={} - ): # pylint: disable=dangerous-default-value + self, user_input=None # pylint: disable=bad-continuation + ): """Handle a flow initialized by the user.""" self._errors = {} + + # Uncomment the next 2 lines if only a single instance of the integration is allowed: + # if self._async_current_entries(): + # return self.async_abort(reason="single_instance_allowed") + if user_input is not None: valid = await self._test_credentials( user_input[CONF_USERNAME], user_input[CONF_PASSWORD] @@ -49,7 +53,7 @@ async def async_step_user( def async_get_options_flow(config_entry): return BlueprintOptionsFlowHandler(config_entry) - async def _show_config_form(self, user_input): + async def _show_config_form(self, user_input): # pylint: disable=unused-argument """Show the configuration form to edit location data.""" return self.async_show_form( step_id="user", @@ -78,7 +82,7 @@ def __init__(self, config_entry): self.config_entry = config_entry self.options = dict(config_entry.options) - async def async_step_init(self, user_input=None): + async def async_step_init(self, user_input=None): # pylint: disable=unused-argument """Manage the options.""" return await self.async_step_user() diff --git a/custom_components/blueprint/entity.py b/custom_components/blueprint/entity.py index 5c181d6..1a64128 100644 --- a/custom_components/blueprint/entity.py +++ b/custom_components/blueprint/entity.py @@ -43,11 +43,9 @@ def device_state_attributes(self): async def async_added_to_hass(self): """Connect to dispatcher listening for entity data notifications.""" - self.coordinator.async_add_listener(self.async_write_ha_state) - - async def async_will_remove_from_hass(self): - """Disconnect from update signal.""" - self.coordinator.async_remove_listener(self.async_write_ha_state) + self.async_on_remove( + self.coordinator.async_add_listener(self.async_write_ha_state) + ) async def async_update(self): """Update Brother entity.""" diff --git a/hacs.json b/hacs.json index e908271..04c51e2 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,11 @@ { "name": "Blueprint", - "hacs": "0.19.0", - "homeassistant": "0.97.0" + "hacs": "0.24.0", + "domains": [ + "binary_sensor", + "sensor", + "switch" + ], + "iot_class": "Cloud Polling", + "homeassistant": "0.108.0" } \ No newline at end of file