From 35a7984175326273d9b2e3a337b0835cf0c3b2ac Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Tue, 17 May 2022 10:28:19 -0600 Subject: [PATCH] Fix sensor to use native unit of measurement and improve reauth flow --- custom_components/vivint/__init__.py | 2 +- custom_components/vivint/config_flow.py | 4 ++-- custom_components/vivint/manifest.json | 16 +++++----------- custom_components/vivint/sensor.py | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/custom_components/vivint/__init__.py b/custom_components/vivint/__init__.py index 10dc05d..229701a 100644 --- a/custom_components/vivint/__init__.py +++ b/custom_components/vivint/__init__.py @@ -60,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except (VivintSkyApiMfaRequiredError, VivintSkyApiAuthenticationError) as ex: raise ConfigEntryAuthFailed(ex) from ex except (VivintSkyApiError, ClientResponseError, ClientConnectorError) as ex: - raise ConfigEntryNotReady from ex + raise ConfigEntryNotReady(ex) from ex dev_reg = await device_registry.async_get_registry(hass) diff --git a/custom_components/vivint/config_flow.py b/custom_components/vivint/config_flow.py index 3bd7ac4..b22e8fc 100644 --- a/custom_components/vivint/config_flow.py +++ b/custom_components/vivint/config_flow.py @@ -64,6 +64,7 @@ async def _async_create_entry(self) -> FlowResult: CONF_PASSWORD: self._hub._data[CONF_PASSWORD], } + await self._hub.disconnect() if existing_entry: self.hass.config_entries.async_update_entry( existing_entry, data=config_data @@ -71,7 +72,6 @@ async def _async_create_entry(self) -> FlowResult: await self.hass.config_entries.async_reload(existing_entry.entry_id) return self.async_abort(reason="reauth_successful") - await self._hub.disconnect() return self.async_create_entry( title=config_data[CONF_USERNAME], data=config_data ) @@ -143,7 +143,7 @@ async def async_step_reauth( self, user_input: dict[str, Any] | None = None ) -> FlowResult: """Perform reauth upon an API authentication error.""" - return await self.async_step_reauth_confirm() + return await self.async_step_reauth_confirm(user_input) async def async_step_reauth_confirm( self, user_input: dict[str, Any] | None = None diff --git a/custom_components/vivint/manifest.json b/custom_components/vivint/manifest.json index f13a35f..5d5e66b 100644 --- a/custom_components/vivint/manifest.json +++ b/custom_components/vivint/manifest.json @@ -1,17 +1,11 @@ { "domain": "vivint", "name": "Vivint", - "version": "2022.4.0", + "version": "2022.5.0", "config_flow": true, "documentation": "https://github.com/natekspencer/hacs-vivint", "issue_tracker": "https://github.com/natekspencer/hacs-vivint/issues", - "requirements": [ - "vivintpy==2022.1.0" - ], - "dependencies": [ - "ffmpeg" - ], - "codeowners": [ - "@natekspencer" - ] -} \ No newline at end of file + "requirements": ["vivintpy==2022.1.0"], + "dependencies": ["ffmpeg"], + "codeowners": ["@natekspencer"] +} diff --git a/custom_components/vivint/sensor.py b/custom_components/vivint/sensor.py index d43a134..a11f64d 100644 --- a/custom_components/vivint/sensor.py +++ b/custom_components/vivint/sensor.py @@ -67,7 +67,7 @@ class VivintBatterySensorEntity(VivintEntity, SensorEntity): _attr_device_class = SensorDeviceClass.BATTERY _attr_entity_category = EntityCategory.DIAGNOSTIC - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE @property def name(self) -> str: