Skip to content

Commit

Permalink
Convert Niko home control to async (#137174)
Browse files Browse the repository at this point in the history
  • Loading branch information
VandeurenGlenn authored Feb 4, 2025
1 parent ffc6aa0 commit a4f0194
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
7 changes: 1 addition & 6 deletions homeassistant/components/niko_home_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from nclib.errors import NetcatError
from nhc.controller import NHCController

from homeassistant.config_entries import ConfigEntry
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/niko_home_control/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/niko_home_control/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ def __init__(
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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/niko_home_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4f0194

Please sign in to comment.