2019-02-19 13:09:06 +00:00
|
|
|
"""Support for INSTEON dimmers via PowerLinc Modem."""
|
2020-08-11 23:04:44 +00:00
|
|
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
|
2022-01-03 18:23:11 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-08-11 23:04:44 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-03 18:23:11 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2020-08-11 23:04:44 +00:00
|
|
|
from .const import SIGNAL_ADD_ENTITIES
|
2020-01-30 09:47:44 +00:00
|
|
|
from .insteon_entity import InsteonEntity
|
2020-05-17 13:27:38 +00:00
|
|
|
from .utils import async_add_insteon_entities
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2022-01-03 18:23:11 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-08-11 23:04:44 +00:00
|
|
|
"""Set up the Insteon switches from a config entry."""
|
|
|
|
|
2021-02-02 09:17:17 +00:00
|
|
|
@callback
|
|
|
|
def async_add_insteon_switch_entities(discovery_info=None):
|
2020-08-11 23:04:44 +00:00
|
|
|
"""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}"
|
2021-02-02 09:17:17 +00:00
|
|
|
async_dispatcher_connect(hass, signal, async_add_insteon_switch_entities)
|
|
|
|
async_add_insteon_switch_entities()
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
|
2020-05-17 13:27:38 +00:00
|
|
|
class InsteonSwitchEntity(InsteonEntity, SwitchEntity):
|
|
|
|
"""A Class for an Insteon switch entity."""
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-07-14 09:04:00 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
2020-05-17 13:27:38 +00:00
|
|
|
return bool(self._insteon_device_group.value)
|
2018-07-14 09:04:00 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn switch on."""
|
|
|
|
await self._insteon_device.async_on(group=self._insteon_device_group.group)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn switch off."""
|
|
|
|
await self._insteon_device.async_off(group=self._insteon_device_group.group)
|