hass-core/homeassistant/components/insteon/switch.py
Tom Harris b1fd931cdc
Add config flow to insteon component (#36467)
* Squashed

* Fix requirements_all

* Update homeassistant/components/insteon/__init__.py

Only update options if the result is to create the entry.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/insteon/__init__.py

No return value needed.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Ref RESULT_TYPE_CREATE_ENTRY correctly

* Return result back to import config process

* Make DOMAIN ref more clear

Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-11 18:04:44 -05:00

42 lines
1.4 KiB
Python

"""Support for INSTEON dimmers via PowerLinc Modem."""
import logging
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import SIGNAL_ADD_ENTITIES
from .insteon_entity import InsteonEntity
from .utils import async_add_insteon_entities
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Insteon switches from a config entry."""
def add_entities(discovery_info=None):
"""Add the Insteon entities for the platform."""
async_add_insteon_entities(
hass, SWITCH_DOMAIN, InsteonSwitchEntity, async_add_entities, discovery_info
)
signal = f"{SIGNAL_ADD_ENTITIES}_{SWITCH_DOMAIN}"
async_dispatcher_connect(hass, signal, add_entities)
add_entities()
class InsteonSwitchEntity(InsteonEntity, SwitchEntity):
"""A Class for an Insteon switch entity."""
@property
def is_on(self):
"""Return the boolean response if the node is on."""
return bool(self._insteon_device_group.value)
async def async_turn_on(self, **kwargs):
"""Turn switch on."""
await self._insteon_device.async_on(group=self._insteon_device_group.group)
async def async_turn_off(self, **kwargs):
"""Turn switch off."""
await self._insteon_device.async_off(group=self._insteon_device_group.group)