From a4f019478620211f5516b88917dceaaf4883470f Mon Sep 17 00:00:00 2001 From: "Glenn Vandeuren (aka Iondependent)" Date: Tue, 4 Feb 2025 14:10:27 +0100 Subject: [PATCH] Convert Niko home control to async (#137174) --- .../components/niko_home_control/__init__.py | 7 +------ homeassistant/components/niko_home_control/cover.py | 12 ++++++------ homeassistant/components/niko_home_control/light.py | 8 ++++---- .../components/niko_home_control/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/niko_home_control/__init__.py b/homeassistant/components/niko_home_control/__init__.py index ae4e8986816..37396e69caa 100644 --- a/homeassistant/components/niko_home_control/__init__.py +++ b/homeassistant/components/niko_home_control/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations -from nclib.errors import NetcatError from nhc.controller import NHCController from homeassistant.config_entries import ConfigEntry @@ -25,12 +24,8 @@ async def async_setup_entry( controller = NHCController(entry.data[CONF_HOST]) try: await controller.connect() - except NetcatError as err: + except (TimeoutError, OSError) as err: raise ConfigEntryNotReady("cannot connect to controller.") from err - except OSError as err: - raise ConfigEntryNotReady( - "unknown error while connecting to controller." - ) from err entry.runtime_data = controller await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/homeassistant/components/niko_home_control/cover.py b/homeassistant/components/niko_home_control/cover.py index 51e2a8a702d..b3546b517d5 100644 --- a/homeassistant/components/niko_home_control/cover.py +++ b/homeassistant/components/niko_home_control/cover.py @@ -37,17 +37,17 @@ class NikoHomeControlCover(NikoHomeControlEntity, CoverEntity): ) _action: NHCCover - def open_cover(self, **kwargs: Any) -> None: + async def async_open_cover(self, **kwargs: Any) -> None: """Open the cover.""" - self._action.open() + await self._action.open() - def close_cover(self, **kwargs: Any) -> None: + async def async_close_cover(self, **kwargs: Any) -> None: """Close the cover.""" - self._action.close() + await self._action.close() - def stop_cover(self, **kwargs: Any) -> None: + async def async_stop_cover(self, **kwargs: Any) -> None: """Stop the cover.""" - self._action.stop() + await self._action.stop() def update_state(self): """Update HA state.""" diff --git a/homeassistant/components/niko_home_control/light.py b/homeassistant/components/niko_home_control/light.py index 5c2b372fd25..7c0d11b3388 100644 --- a/homeassistant/components/niko_home_control/light.py +++ b/homeassistant/components/niko_home_control/light.py @@ -109,13 +109,13 @@ class NikoHomeControlLight(NikoHomeControlEntity, LightEntity): self._attr_supported_color_modes = {ColorMode.BRIGHTNESS} self._attr_brightness = round(action.state * 2.55) - def turn_on(self, **kwargs: Any) -> None: + async def async_turn_on(self, **kwargs: Any) -> None: """Instruct the light to turn on.""" - self._action.turn_on(round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)) + await self._action.turn_on(round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)) - def turn_off(self, **kwargs: Any) -> None: + async def async_turn_off(self, **kwargs: Any) -> None: """Instruct the light to turn off.""" - self._action.turn_off() + await self._action.turn_off() def update_state(self) -> None: """Handle updates from the controller.""" diff --git a/homeassistant/components/niko_home_control/manifest.json b/homeassistant/components/niko_home_control/manifest.json index 57f83180eb0..b50410cd7de 100644 --- a/homeassistant/components/niko_home_control/manifest.json +++ b/homeassistant/components/niko_home_control/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/niko_home_control", "iot_class": "local_push", "loggers": ["nikohomecontrol"], - "requirements": ["nhc==0.3.9"] + "requirements": ["nhc==0.4.4"] } diff --git a/requirements_all.txt b/requirements_all.txt index f8ad3dbb3ab..ac62beec307 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1486,7 +1486,7 @@ nextcord==2.6.0 nextdns==4.0.0 # homeassistant.components.niko_home_control -nhc==0.3.9 +nhc==0.4.4 # homeassistant.components.nibe_heatpump nibe==2.14.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index cc03af9ce82..eb564f7e056 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1249,7 +1249,7 @@ nextcord==2.6.0 nextdns==4.0.0 # homeassistant.components.niko_home_control -nhc==0.3.9 +nhc==0.4.4 # homeassistant.components.nibe_heatpump nibe==2.14.0