hass-core/homeassistant/components/supla/switch.py
Michał Węgrzynek 8818a5ab6c
Use DataUpdateCoordinator for supla (#38921)
* Linter suggestions

* Store coordinator in hass.data[supla_coordinators]

* Server cleanup

* Spelling mistake

* Fixes suggested in review

* Pass server and coordinator during async_setup_platform

* Linter changes

* Rename fetch_channels to _fetch_channels

* Linter suggestions

* Store coordinator in hass.data[supla_coordinators]

* Server cleanup

* Fixes suggested in review

* Pass server and coordinator during async_setup_platform

* Linter changes

* Remove scan interval configuration option

* Linting

* Isort

* Disable polling, update asyncpysupla version

* Black fixes

* Update manifest.json

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-09-03 11:25:30 -05:00

55 lines
1.4 KiB
Python

"""Support for Supla switch."""
import logging
from pprint import pformat
from homeassistant.components.supla import (
DOMAIN,
SUPLA_COORDINATORS,
SUPLA_SERVERS,
SuplaChannel,
)
from homeassistant.components.switch import SwitchEntity
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Supla switches."""
if discovery_info is None:
return
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
entities = []
for device in discovery_info:
server_name = device["server_name"]
entities.append(
SuplaSwitch(
device,
hass.data[DOMAIN][SUPLA_SERVERS][server_name],
hass.data[DOMAIN][SUPLA_COORDINATORS][server_name],
)
)
async_add_entities(entities)
class SuplaSwitch(SuplaChannel, SwitchEntity):
"""Representation of a Supla Switch."""
async def async_turn_on(self, **kwargs):
"""Turn on the switch."""
await self.async_action("TURN_ON")
async def async_turn_off(self, **kwargs):
"""Turn off the switch."""
await self.async_action("TURN_OFF")
@property
def is_on(self):
"""Return true if switch is on."""
state = self.channel_data.get("state")
if state:
return state["on"]
return False