-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
959f20c
commit dad2bae
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Setup NikoHomeControlcover.""" | ||
|
||
from __future__ import annotations | ||
|
||
from nhc.cover import NHCCover | ||
|
||
from homeassistant.components.cover import CoverEntity, CoverEntityFeature | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from . import NHCController, NikoHomeControlConfigEntry | ||
from .entity import NikoHomeControlEntity | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
entry: NikoHomeControlConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the Niko Home Control cover entry.""" | ||
controller = entry.runtime_data | ||
|
||
async_add_entities( | ||
NikoHomeControlCover(cover, controller, entry.entry_id) | ||
for cover in controller.covers | ||
) | ||
|
||
|
||
class NikoHomeControlCover(NikoHomeControlEntity, CoverEntity): | ||
"""Representation of a Niko Cover.""" | ||
|
||
_attr_name = None | ||
_action = NHCCover | ||
|
||
def __init__( | ||
self, action: NHCCover, controller: NHCController, unique_id: str | ||
) -> None: | ||
"""Set up the Niko Home Control cover.""" | ||
super().__init__(action, controller, unique_id) | ||
self._attr_supported_features = ( | ||
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP | ||
) | ||
|
||
def open_cover(self): | ||
"""Open the cover.""" | ||
self._action.open() | ||
|
||
def close_cover(self): | ||
"""Close the cover.""" | ||
self._action.close() | ||
|
||
def stop_cover(self): | ||
"""Stop the cover.""" | ||
self._action.stop() | ||
|
||
def update_state(self): | ||
"""Update HA state.""" | ||
self._attr_is_closed = self._action.state == 0 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Setup NikoHomeControlFan.""" | ||
|
||
from nhc.fan import NHCFan | ||
|
||
from homeassistant.components.fan import FanEntity, FanEntityFeature | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from . import NHCController, NikoHomeControlConfigEntry | ||
from .const import PRESET_MODES | ||
from .entity import NikoHomeControlEntity | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
entry: NikoHomeControlConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the Niko Home Control fan entry.""" | ||
controller = entry.runtime_data | ||
|
||
async_add_entities( | ||
NikoHomeControlFan(fan, controller, entry.entry_id) for fan in controller.fans | ||
) | ||
|
||
|
||
class NikoHomeControlFan(NikoHomeControlEntity, FanEntity): | ||
"""Representation of an Niko fan.""" | ||
|
||
_attr_name = None | ||
_action = NHCFan | ||
|
||
def __init__( | ||
self, action: NHCFan, controller: NHCController, unique_id: str | ||
) -> None: | ||
"""Set up the Niko Home Control fan platform.""" | ||
super().__init__(action, controller, unique_id) | ||
self._attr_preset_modes = PRESET_MODES | ||
self._attr_supported_features = FanEntityFeature.PRESET_MODE | ||
self._attr_enable_turn_on_off_backwards_compatibility = False | ||
|
||
def set_preset_mode(self, preset_mode: str) -> None: | ||
"""Set the preset mode of the fan.""" | ||
self._action.set_mode(preset_mode) | ||
|
||
def update_state(self) -> None: | ||
"""Handle updates from the controller.""" | ||
self._attr_preset_mode = PRESET_MODES[self._action.state] | ||