cgtobi 2c07bfb9e0 Remove dependencies and requirements (#23024)
* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit fe7171b4cd30889bad5adc9a4fd60059d05ba5a7.

* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit 391355ee2cc53cbe6954f940062b18ae34b05621.

* Remove dependencies and requirements

* Fix flake8 complaints

* Fix more flake8 complaints

* Revert non-component removals
2019-04-12 10:13:30 -07:00

66 lines
1.7 KiB
Python

"""Support for Eufy switches."""
import logging
from homeassistant.components.switch import SwitchDevice
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Eufy switches."""
if discovery_info is None:
return
add_entities([EufySwitch(discovery_info)], True)
class EufySwitch(SwitchDevice):
"""Representation of a Eufy switch."""
def __init__(self, device):
"""Initialize the light."""
import lakeside
self._state = None
self._name = device['name']
self._address = device['address']
self._code = device['code']
self._type = device['type']
self._switch = lakeside.switch(self._address, self._code, self._type)
self._switch.connect()
def update(self):
"""Synchronise state from the switch."""
self._switch.update()
self._state = self._switch.power
@property
def unique_id(self):
"""Return the ID of this light."""
return self._address
@property
def name(self):
"""Return the name of the device if any."""
return self._name
@property
def is_on(self):
"""Return true if device is on."""
return self._state
def turn_on(self, **kwargs):
"""Turn the specified switch on."""
try:
self._switch.set_state(True)
except BrokenPipeError:
self._switch.connect()
self._switch.set_state(power=True)
def turn_off(self, **kwargs):
"""Turn the specified switch off."""
try:
self._switch.set_state(False)
except BrokenPipeError:
self._switch.connect()
self._switch.set_state(False)