1 """Support for w800rf32 devices."""
5 import voluptuous
as vol
6 import W800rf32
as w800
10 EVENT_HOMEASSISTANT_START,
11 EVENT_HOMEASSISTANT_STOP,
18 DATA_W800RF32 =
"data_w800rf32"
21 W800RF32_DEVICE =
"w800rf32_{}"
23 _LOGGER = logging.getLogger(__name__)
25 CONFIG_SCHEMA = vol.Schema(
26 {DOMAIN: vol.Schema({vol.Required(CONF_DEVICE): cv.string})}, extra=vol.ALLOW_EXTRA
30 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
31 """Set up the w800rf32 component."""
34 def handle_receive(event):
35 """Handle received messages from w800rf32 gateway."""
39 _LOGGER.debug(
"Receive W800rf32 event in handle_receive")
42 device_id = event.device.lower()
43 signal = W800RF32_DEVICE.format(device_id)
47 device = config[DOMAIN][CONF_DEVICE]
48 w800_object = w800.Connect(device,
None)
50 def _start_w800rf32(event):
51 w800_object.event_callback = handle_receive
53 hass.bus.listen_once(EVENT_HOMEASSISTANT_START, _start_w800rf32)
55 def _shutdown_w800rf32(event):
56 """Close connection with w800rf32."""
57 w800_object.close_connection()
59 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown_w800rf32)
61 hass.data[DATA_W800RF32] = w800_object
bool setup(HomeAssistant hass, ConfigType config)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)