hass-core/homeassistant/components/w800rf32.py
horga83 8f107c46fe W800rf32 (#17920)
* Initial commit of w800rf32 component and binary_sensor.

The W800 family is an X10 RF receiver used with keypads and motion sensors etc.

* Initial commit of w800rf32 switch platform.

The W800 family is an X10 RF receiver used with keypads and motion sensors etc.

* Remove unused code.

* Additions for w800rf32 component and platform code

* Fix w800rf32 minor lint issues and make sure gen_requirements.py correctlly adds w800rf32

* Added dispatch_connect/send and refactor somewhat

* Fix missed indentation lint

* Removed shared entity dict and use async_dispatch code

* Fix long line not caught by lint

* One more line too long, missed it

* Remove unused code and changes for async

* Remove  @callback that shouldn't be there.

* Remove switch platform, can't have read only switch.

* Remove unused CONF_DEBUG

* Remove used vars and make CONF_DEVICES required

* Move CONF_OFF_DELAY to platform, only used there
2018-11-08 18:49:00 +01:00

67 lines
1.8 KiB
Python

"""
Support for w800rf32 components.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/w800rf32/
"""
import logging
import voluptuous as vol
from homeassistant.const import (CONF_DEVICE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import (dispatcher_send)
REQUIREMENTS = ['pyW800rf32==0.1']
DOMAIN = 'w800rf32'
DATA_W800RF32 = 'data_w800rf32'
W800RF32_DEVICE = 'w800rf32_{}'
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_DEVICE): cv.string
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
"""Set up the w800rf32 component."""
# Try to load the W800rf32 module.
import W800rf32 as w800
# Declare the Handle event
def handle_receive(event):
"""Handle received messages from w800rf32 gateway."""
# Log event
if not event.device:
return
_LOGGER.debug("Receive W800rf32 event in handle_receive")
# Get device_type from device_id in hass.data
device_id = event.device.lower()
signal = W800RF32_DEVICE.format(device_id)
dispatcher_send(hass, signal, event)
# device --> /dev/ttyUSB0
device = config[DOMAIN][CONF_DEVICE]
w800_object = w800.Connect(device, None)
def _start_w800rf32(event):
w800_object.event_callback = handle_receive
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, _start_w800rf32)
def _shutdown_w800rf32(event):
"""Close connection with w800rf32."""
w800_object.close_connection()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown_w800rf32)
hass.data[DATA_W800RF32] = w800_object
return True