Convert Niko home control to async (#137174)

This commit is contained in:
Glenn Vandeuren (aka Iondependent) 2025-02-04 14:10:27 +01:00 committed by GitHub
parent ffc6aa0035
commit a4f0194786
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 19 deletions

View File

@ -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)

View File

@ -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."""

View File

@ -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."""

View File

@ -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"]
}

2
requirements_all.txt generated
View File

@ -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

View File

@ -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