mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Setup rfxtrx event listener directly (#38298)
This commit is contained in:
parent
1158925b53
commit
c3966a5ef2
@ -18,7 +18,6 @@ from homeassistant.const import (
|
|||||||
CONF_DEVICES,
|
CONF_DEVICES,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_START,
|
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
POWER_WATT,
|
POWER_WATT,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
@ -289,23 +288,17 @@ async def async_setup_internal(hass, entry: config_entries.ConfigEntry):
|
|||||||
hass.config_entries.async_update_entry(entry=entry, data=data)
|
hass.config_entries.async_update_entry(entry=entry, data=data)
|
||||||
devices[device_id] = config
|
devices[device_id] = config
|
||||||
|
|
||||||
@callback
|
|
||||||
def _start_rfxtrx(event):
|
|
||||||
"""Start receiving events."""
|
|
||||||
rfx_object.event_callback = lambda event: hass.add_job(
|
|
||||||
async_handle_receive, event
|
|
||||||
)
|
|
||||||
|
|
||||||
def _shutdown_rfxtrx(event):
|
def _shutdown_rfxtrx(event):
|
||||||
"""Close connection with RFXtrx."""
|
"""Close connection with RFXtrx."""
|
||||||
rfx_object.close_connection()
|
rfx_object.close_connection()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _start_rfxtrx)
|
|
||||||
listener = hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown_rfxtrx)
|
listener = hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown_rfxtrx)
|
||||||
|
|
||||||
hass.data[DOMAIN][DATA_LISTENER] = listener
|
hass.data[DOMAIN][DATA_LISTENER] = listener
|
||||||
hass.data[DOMAIN][DATA_RFXOBJECT] = rfx_object
|
hass.data[DOMAIN][DATA_RFXOBJECT] = rfx_object
|
||||||
|
|
||||||
|
rfx_object.event_callback = lambda event: hass.add_job(async_handle_receive, event)
|
||||||
|
|
||||||
def send(call):
|
def send(call):
|
||||||
event = call.data[ATTR_EVENT]
|
event = call.data[ATTR_EVENT]
|
||||||
rfx_object.transport.send(event)
|
rfx_object.transport.send(event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user