forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dynalite switch platform (home-assistant#32389)
* added presets for switch devices * added channel type to __init and const * ran pylint on library so needed a few changes in names * removed callback * bool -> cv.boolean
- Loading branch information
Showing
13 changed files
with
134 additions
and
31 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
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,29 @@ | ||
"""Support for the Dynalite channels and presets as switches.""" | ||
from homeassistant.components.switch import SwitchDevice | ||
|
||
from .dynalitebase import DynaliteBase, async_setup_entry_base | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Record the async_add_entities function to add them later when received from Dynalite.""" | ||
|
||
async_setup_entry_base( | ||
hass, config_entry, async_add_entities, "switch", DynaliteSwitch | ||
) | ||
|
||
|
||
class DynaliteSwitch(DynaliteBase, SwitchDevice): | ||
"""Representation of a Dynalite Channel as a Home Assistant Switch.""" | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if switch is on.""" | ||
return self._device.is_on | ||
|
||
async def async_turn_on(self, **kwargs): | ||
"""Turn the switch on.""" | ||
await self._device.async_turn_on() | ||
|
||
async def async_turn_off(self, **kwargs): | ||
"""Turn the switch off.""" | ||
await self._device.async_turn_off() |
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
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,34 @@ | ||
"""Test Dynalite switch.""" | ||
|
||
from dynalite_devices_lib.switch import DynalitePresetSwitchDevice | ||
import pytest | ||
|
||
from .common import ( | ||
ATTR_METHOD, | ||
ATTR_SERVICE, | ||
create_entity_from_device, | ||
create_mock_device, | ||
run_service_tests, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def mock_device(): | ||
"""Mock a Dynalite device.""" | ||
return create_mock_device("switch", DynalitePresetSwitchDevice) | ||
|
||
|
||
async def test_switch_setup(hass, mock_device): | ||
"""Test a successful setup.""" | ||
await create_entity_from_device(hass, mock_device) | ||
entity_state = hass.states.get("switch.name") | ||
assert entity_state.attributes["friendly_name"] == mock_device.name | ||
await run_service_tests( | ||
hass, | ||
mock_device, | ||
"switch", | ||
[ | ||
{ATTR_SERVICE: "turn_on", ATTR_METHOD: "async_turn_on"}, | ||
{ATTR_SERVICE: "turn_off", ATTR_METHOD: "async_turn_off"}, | ||
], | ||
) |