Skip to content

Commit

Permalink
Add fan and cover
Browse files Browse the repository at this point in the history
  • Loading branch information
VandeurenGlenn committed Dec 22, 2024
1 parent 959f20c commit dad2bae
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/niko_home_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .const import _LOGGER

PLATFORMS: list[Platform] = [Platform.LIGHT]
PLATFORMS: list[Platform] = [Platform.COVER, Platform.FAN, Platform.LIGHT]

type NikoHomeControlConfigEntry = ConfigEntry[NHCController]

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/niko_home_control/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import logging

DOMAIN = "niko_home_control"
PRESET_MODES = ["low", "medium", "high", "boost"]
_LOGGER = logging.getLogger(__name__)
58 changes: 58 additions & 0 deletions homeassistant/components/niko_home_control/cover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Setup NikoHomeControlcover."""

from __future__ import annotations

Check warning on line 3 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L3

Added line #L3 was not covered by tests

from nhc.cover import NHCCover

Check warning on line 5 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L5

Added line #L5 was not covered by tests

from homeassistant.components.cover import CoverEntity, CoverEntityFeature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check warning on line 9 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L7-L9

Added lines #L7 - L9 were not covered by tests

from . import NHCController, NikoHomeControlConfigEntry
from .entity import NikoHomeControlEntity

Check warning on line 12 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L11-L12

Added lines #L11 - L12 were not covered by tests


async def async_setup_entry(

Check warning on line 15 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L15

Added line #L15 was not covered by tests
hass: HomeAssistant,
entry: NikoHomeControlConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Niko Home Control cover entry."""
controller = entry.runtime_data

Check warning on line 21 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L21

Added line #L21 was not covered by tests

async_add_entities(

Check warning on line 23 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L23

Added line #L23 was not covered by tests
NikoHomeControlCover(cover, controller, entry.entry_id)
for cover in controller.covers
)


class NikoHomeControlCover(NikoHomeControlEntity, CoverEntity):

Check warning on line 29 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L29

Added line #L29 was not covered by tests
"""Representation of a Niko Cover."""

_attr_name = None
_action = NHCCover

Check warning on line 33 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L32-L33

Added lines #L32 - L33 were not covered by tests

def __init__(

Check warning on line 35 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L35

Added line #L35 was not covered by tests
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 = (

Check warning on line 40 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L39-L40

Added lines #L39 - L40 were not covered by tests
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)

def open_cover(self):

Check warning on line 44 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L44

Added line #L44 was not covered by tests
"""Open the cover."""
self._action.open()

Check warning on line 46 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L46

Added line #L46 was not covered by tests

def close_cover(self):

Check warning on line 48 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L48

Added line #L48 was not covered by tests
"""Close the cover."""
self._action.close()

Check warning on line 50 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L50

Added line #L50 was not covered by tests

def stop_cover(self):

Check warning on line 52 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L52

Added line #L52 was not covered by tests
"""Stop the cover."""
self._action.stop()

Check warning on line 54 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L54

Added line #L54 was not covered by tests

def update_state(self):

Check warning on line 56 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L56

Added line #L56 was not covered by tests
"""Update HA state."""
self._attr_is_closed = self._action.state == 0

Check warning on line 58 in homeassistant/components/niko_home_control/cover.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/cover.py#L58

Added line #L58 was not covered by tests
48 changes: 48 additions & 0 deletions homeassistant/components/niko_home_control/fan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Setup NikoHomeControlFan."""

from nhc.fan import NHCFan

Check warning on line 3 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L3

Added line #L3 was not covered by tests

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check warning on line 7 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L5-L7

Added lines #L5 - L7 were not covered by tests

from . import NHCController, NikoHomeControlConfigEntry
from .const import PRESET_MODES
from .entity import NikoHomeControlEntity

Check warning on line 11 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L9-L11

Added lines #L9 - L11 were not covered by tests


async def async_setup_entry(

Check warning on line 14 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L14

Added line #L14 was not covered by tests
hass: HomeAssistant,
entry: NikoHomeControlConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Niko Home Control fan entry."""
controller = entry.runtime_data

Check warning on line 20 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L20

Added line #L20 was not covered by tests

async_add_entities(

Check warning on line 22 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L22

Added line #L22 was not covered by tests
NikoHomeControlFan(fan, controller, entry.entry_id) for fan in controller.fans
)


class NikoHomeControlFan(NikoHomeControlEntity, FanEntity):

Check warning on line 27 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L27

Added line #L27 was not covered by tests
"""Representation of an Niko fan."""

_attr_name = None
_action = NHCFan

Check warning on line 31 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L30-L31

Added lines #L30 - L31 were not covered by tests

def __init__(

Check warning on line 33 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L33

Added line #L33 was not covered by tests
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

Check warning on line 40 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L37-L40

Added lines #L37 - L40 were not covered by tests

def set_preset_mode(self, preset_mode: str) -> None:

Check warning on line 42 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L42

Added line #L42 was not covered by tests
"""Set the preset mode of the fan."""
self._action.set_mode(preset_mode)

Check warning on line 44 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L44

Added line #L44 was not covered by tests

def update_state(self) -> None:

Check warning on line 46 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L46

Added line #L46 was not covered by tests
"""Handle updates from the controller."""
self._attr_preset_mode = PRESET_MODES[self._action.state]

Check warning on line 48 in homeassistant/components/niko_home_control/fan.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/fan.py#L48

Added line #L48 was not covered by tests

0 comments on commit dad2bae

Please sign in to comment.