2015-03-09 01:14:44 +11:00
|
|
|
"""
|
|
|
|
Support for Vera switches.
|
2015-03-07 14:49:20 +11:00
|
|
|
|
2015-10-20 22:08:20 +02:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 13:12:18 +01:00
|
|
|
https://home-assistant.io/components/switch.vera/
|
2015-03-07 14:49:20 +11:00
|
|
|
"""
|
2015-03-02 21:09:00 +11:00
|
|
|
import logging
|
2016-02-18 21:27:50 -08:00
|
|
|
|
2016-07-20 04:13:33 +02:00
|
|
|
from homeassistant.util import convert
|
2017-03-11 18:06:46 +00:00
|
|
|
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchDevice
|
2016-03-15 09:17:09 +00:00
|
|
|
from homeassistant.components.vera import (
|
2017-03-11 18:06:46 +00:00
|
|
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
2015-09-08 20:11:25 -07:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
DEPENDENCIES = ['vera']
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2015-03-08 23:52:50 +11:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2015-03-09 01:58:11 +11:00
|
|
|
|
2018-08-24 16:37:30 +02:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Set up the Vera switches."""
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities(
|
2018-06-07 15:31:21 -04:00
|
|
|
[VeraSwitch(device, hass.data[VERA_CONTROLLER]) for
|
|
|
|
device in hass.data[VERA_DEVICES]['switch']], True)
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2015-03-09 01:58:11 +11:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
class VeraSwitch(VeraDevice, SwitchDevice):
|
2016-03-08 13:35:39 +01:00
|
|
|
"""Representation of a Vera Switch."""
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
def __init__(self, vera_device, controller):
|
2016-03-08 13:35:39 +01:00
|
|
|
"""Initialize the Vera device."""
|
2016-03-15 09:17:09 +00:00
|
|
|
self._state = False
|
|
|
|
VeraDevice.__init__(self, vera_device, controller)
|
2017-03-11 18:06:46 +00:00
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
2015-03-02 21:09:00 +11:00
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
2016-03-08 13:35:39 +01:00
|
|
|
"""Turn device on."""
|
2015-03-02 21:09:00 +11:00
|
|
|
self.vera_device.switch_on()
|
2017-04-04 11:02:09 +01:00
|
|
|
self._state = True
|
2016-11-16 08:26:29 -08:00
|
|
|
self.schedule_update_ha_state()
|
2015-03-02 21:09:00 +11:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2016-03-08 13:35:39 +01:00
|
|
|
"""Turn device off."""
|
2015-03-02 21:09:00 +11:00
|
|
|
self.vera_device.switch_off()
|
2017-04-04 11:02:09 +01:00
|
|
|
self._state = False
|
2016-11-16 08:26:29 -08:00
|
|
|
self.schedule_update_ha_state()
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2016-07-20 04:13:33 +02:00
|
|
|
@property
|
2017-03-19 21:02:11 +00:00
|
|
|
def current_power_w(self):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Return the current power usage in W."""
|
2016-07-20 04:13:33 +02:00
|
|
|
power = self.vera_device.power
|
|
|
|
if power:
|
2017-03-19 21:02:11 +00:00
|
|
|
return convert(power, float, 0.0)
|
2016-07-20 04:13:33 +02:00
|
|
|
|
2015-03-02 21:09:00 +11:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-08 13:35:39 +01:00
|
|
|
"""Return true if device is on."""
|
2016-03-15 09:17:09 +00:00
|
|
|
return self._state
|
2016-01-15 21:30:58 +00:00
|
|
|
|
|
|
|
def update(self):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Update device state."""
|
2016-03-15 09:17:09 +00:00
|
|
|
self._state = self.vera_device.is_switched_on()
|