-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Showing
10 changed files
with
101 additions
and
6 deletions.
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
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,50 @@ | ||
"""Nice G.O. switch platform.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from . import NiceGOConfigEntry | ||
from .entity import NiceGOEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: NiceGOConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up Nice G.O. cover.""" | ||
coordinator = config_entry.runtime_data | ||
|
||
async_add_entities( | ||
NiceGOSwitchEntity(coordinator, device_id, device_data.name, "switch") | ||
for device_id, device_data in coordinator.data.items() | ||
) | ||
|
||
|
||
class NiceGOSwitchEntity(NiceGOEntity, SwitchEntity): | ||
"""Representation of a Nice G.O. switch.""" | ||
|
||
_attr_device_class = SwitchDeviceClass.SWITCH | ||
_attr_icon = "mdi:beach" | ||
_attr_translation_key = "vacation_mode" | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return if switch is on.""" | ||
return self.data.vacation_mode | ||
|
||
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Turn the switch on.""" | ||
await self.coordinator.api.vacation_mode_on(self.data.id) | ||
|
||
async def async_turn_off(self, **kwargs: Any) -> None: | ||
"""Turn the switch off.""" | ||
await self.coordinator.api.vacation_mode_off(self.data.id) |
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
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,37 @@ | ||
"""Nice G.O. switch tests.""" | ||
|
||
from unittest.mock import AsyncMock | ||
|
||
from homeassistant.core import HomeAssistant | ||
|
||
from . import setup_integration | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def test_turn_on( | ||
hass: HomeAssistant, mock_nice_go: AsyncMock, mock_config_entry: MockConfigEntry | ||
) -> None: | ||
"""Test turn on switch.""" | ||
await setup_integration(hass, mock_config_entry, ["switch"]) | ||
await hass.services.async_call( | ||
"switch", | ||
"turn_on", | ||
{"entity_id": "switch.test_garage_1_vacation_mode"}, | ||
blocking=True, | ||
) | ||
mock_nice_go.vacation_mode_on.assert_called_once_with("1") | ||
|
||
|
||
async def test_turn_off( | ||
hass: HomeAssistant, mock_nice_go: AsyncMock, mock_config_entry: MockConfigEntry | ||
) -> None: | ||
"""Test turn off switch.""" | ||
await setup_integration(hass, mock_config_entry, ["switch"]) | ||
await hass.services.async_call( | ||
"switch", | ||
"turn_off", | ||
{"entity_id": "switch.test_garage_2_vacation_mode"}, | ||
blocking=True, | ||
) | ||
mock_nice_go.vacation_mode_off.assert_called_once_with("2") |