Files
home-assistant-core/homeassistant/components/dynalite/switch.py
T
ZivandMartin Hjelmare 39408ab240 Add cover platform to Dynalite (#32594)
* lib version

* unit-test refactoring

* added type hints

* added cover

* added test to see that consts have the same value as library consts

* Update tests/components/dynalite/test_init.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* removed trigger template

* Update homeassistant/components/dynalite/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/dynalite/const.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* removed CONF_TRIGGER from const
corrected type hints - not clear why mypy didn't catch it

* conversion of the config to library CONFs

* moved to use the value since it should come from the library

* taking CONF_HOST from homeassistant.const instead of module const

* use dict.get
removed leftover log

* force device_class to be from homeassistant consts

* move dict.get to inline

* removed CONF from values
changed "channelcover" to "channel_cover"

* moved some CONF values out of const.py and taking them from homeassistant.const

* verifying that device class is a valid HA device class

* moved shutter to home assistant const

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-04-02 20:26:36 +02:00

36 lines
1.1 KiB
Python
Executable File

"""Support for the Dynalite channels and presets as switches."""
from typing import Callable
from homeassistant.components.switch import SwitchDevice
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .dynalitebase import DynaliteBase, async_setup_entry_base
async def async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
) -> None:
"""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) -> bool:
"""Return true if switch is on."""
return self._device.is_on
async def async_turn_on(self, **kwargs) -> None:
"""Turn the switch on."""
await self._device.async_turn_on()
async def async_turn_off(self, **kwargs) -> None:
"""Turn the switch off."""
await self._device.async_turn_off()