mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Convert Niko home control to async (#137174)
This commit is contained in:
parent
ffc6aa0035
commit
a4f0194786
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from nclib.errors import NetcatError
|
|
||||||
from nhc.controller import NHCController
|
from nhc.controller import NHCController
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -25,12 +24,8 @@ async def async_setup_entry(
|
|||||||
controller = NHCController(entry.data[CONF_HOST])
|
controller = NHCController(entry.data[CONF_HOST])
|
||||||
try:
|
try:
|
||||||
await controller.connect()
|
await controller.connect()
|
||||||
except NetcatError as err:
|
except (TimeoutError, OSError) as err:
|
||||||
raise ConfigEntryNotReady("cannot connect to controller.") from 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
|
entry.runtime_data = controller
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
@ -37,17 +37,17 @@ class NikoHomeControlCover(NikoHomeControlEntity, CoverEntity):
|
|||||||
)
|
)
|
||||||
_action: NHCCover
|
_action: NHCCover
|
||||||
|
|
||||||
def open_cover(self, **kwargs: Any) -> None:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""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."""
|
"""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."""
|
"""Stop the cover."""
|
||||||
self._action.stop()
|
await self._action.stop()
|
||||||
|
|
||||||
def update_state(self):
|
def update_state(self):
|
||||||
"""Update HA state."""
|
"""Update HA state."""
|
||||||
|
@ -109,13 +109,13 @@ class NikoHomeControlLight(NikoHomeControlEntity, LightEntity):
|
|||||||
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
self._attr_brightness = round(action.state * 2.55)
|
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."""
|
"""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."""
|
"""Instruct the light to turn off."""
|
||||||
self._action.turn_off()
|
await self._action.turn_off()
|
||||||
|
|
||||||
def update_state(self) -> None:
|
def update_state(self) -> None:
|
||||||
"""Handle updates from the controller."""
|
"""Handle updates from the controller."""
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/niko_home_control",
|
"documentation": "https://www.home-assistant.io/integrations/niko_home_control",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"loggers": ["nikohomecontrol"],
|
"loggers": ["nikohomecontrol"],
|
||||||
"requirements": ["nhc==0.3.9"]
|
"requirements": ["nhc==0.4.4"]
|
||||||
}
|
}
|
||||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -1486,7 +1486,7 @@ nextcord==2.6.0
|
|||||||
nextdns==4.0.0
|
nextdns==4.0.0
|
||||||
|
|
||||||
# homeassistant.components.niko_home_control
|
# homeassistant.components.niko_home_control
|
||||||
nhc==0.3.9
|
nhc==0.4.4
|
||||||
|
|
||||||
# homeassistant.components.nibe_heatpump
|
# homeassistant.components.nibe_heatpump
|
||||||
nibe==2.14.0
|
nibe==2.14.0
|
||||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -1249,7 +1249,7 @@ nextcord==2.6.0
|
|||||||
nextdns==4.0.0
|
nextdns==4.0.0
|
||||||
|
|
||||||
# homeassistant.components.niko_home_control
|
# homeassistant.components.niko_home_control
|
||||||
nhc==0.3.9
|
nhc==0.4.4
|
||||||
|
|
||||||
# homeassistant.components.nibe_heatpump
|
# homeassistant.components.nibe_heatpump
|
||||||
nibe==2.14.0
|
nibe==2.14.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user