* add ads hub, light and switch
* add binary sensor prototype
* switch: use adsvar for connection
* fix some issues with binary sensor
* fix binary sensor
* fix all platforms
* use latest pyads
* fixed error with multiple binary sensors
* add sensor
* add ads sensor
* clean up after shutdown
* ads component with platforms switch, binary_sensor, light, sensor
add locking
poll sensors at startup
update state of ads switch and light
update ads requirements
remove update() from constructors on ads platforms
omit ads coverage
ads catch read error when polling
* add ads service
* add default settings for use_notify and poll_interval
* fix too long line
* Fix style issues
* no pydocstyle errors
* Send and receive native brightness data to ADS device to prevent issues with math.floor reducing brightness -1 at every switch
* Enable non dimmable lights
* remove setting of self._state in switch
* remove polling
* Revert "remove polling"
This reverts commit 7da420f823
.
* add service schema, add links to documentation
* fix naming, cleanup
* re-remove polling
* use async_added_to_hass for setup of callbacks
* fix comment.
* add callbacks for changed values
* use async_add_job for creating device notifications
* set should_poll to False for all platforms
* change should_poll to property
* add service description to services.yaml
* add for brigthness not being None
* put ads component in package
* Remove whitespace
* omit ads package
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
"""
|
|
Support for ADS binary sensors.
|
|
|
|
For more details about this platform, please refer to the documentation.
|
|
https://home-assistant.io/components/binary_sensor.ads/
|
|
|
|
"""
|
|
import asyncio
|
|
import logging
|
|
import voluptuous as vol
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice, \
|
|
PLATFORM_SCHEMA, DEVICE_CLASSES_SCHEMA
|
|
from homeassistant.components.ads import DATA_ADS, CONF_ADS_VAR
|
|
from homeassistant.const import CONF_NAME, CONF_DEVICE_CLASS
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
DEPENDENCIES = ['ads']
|
|
DEFAULT_NAME = 'ADS binary sensor'
|
|
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Required(CONF_ADS_VAR): cv.string,
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
|
})
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
"""Set up the Binary Sensor platform for ADS."""
|
|
ads_hub = hass.data.get(DATA_ADS)
|
|
|
|
ads_var = config.get(CONF_ADS_VAR)
|
|
name = config.get(CONF_NAME)
|
|
device_class = config.get(CONF_DEVICE_CLASS)
|
|
|
|
ads_sensor = AdsBinarySensor(ads_hub, name, ads_var, device_class)
|
|
add_devices([ads_sensor])
|
|
|
|
|
|
class AdsBinarySensor(BinarySensorDevice):
|
|
"""Representation of ADS binary sensors."""
|
|
|
|
def __init__(self, ads_hub, name, ads_var, device_class):
|
|
"""Initialize AdsBinarySensor entity."""
|
|
self._name = name
|
|
self._state = False
|
|
self._device_class = device_class or 'moving'
|
|
self._ads_hub = ads_hub
|
|
self.ads_var = ads_var
|
|
|
|
@asyncio.coroutine
|
|
def async_added_to_hass(self):
|
|
"""Register device notification."""
|
|
def update(name, value):
|
|
"""Handle device notifications."""
|
|
_LOGGER.debug('Variable %s changed its value to %d',
|
|
name, value)
|
|
self._state = value
|
|
self.schedule_update_ha_state()
|
|
|
|
self.hass.async_add_job(
|
|
self._ads_hub.add_device_notification,
|
|
self.ads_var, self._ads_hub.PLCTYPE_BOOL, update
|
|
)
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the default name of the binary sensor."""
|
|
return self._name
|
|
|
|
@property
|
|
def device_class(self):
|
|
"""Return the device class."""
|
|
return self._device_class
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return if the binary sensor is on."""
|
|
return self._state
|
|
|
|
@property
|
|
def should_poll(self):
|
|
"""Return False because entity pushes its state to HA."""
|
|
return False
|