Switch rfxtrx to config entries (#37794)

* Switch to config flow setup

* Add minimal test for config flow

* Add myself as codeowner and address some review concerns

* Address some further review comments
This commit is contained in:
Joakim Plate 2020-07-13 23:24:28 +02:00 committed by GitHub
parent ed3f25489e
commit 1a64108eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 228 additions and 71 deletions

View file

@ -3,6 +3,7 @@ import logging
from homeassistant.components.cover import CoverEntity
from homeassistant.const import CONF_DEVICES, STATE_OPEN
from homeassistant.core import callback
from homeassistant.helpers.restore_state import RestoreEntity
from . import (
@ -14,16 +15,16 @@ from . import (
get_device_id,
get_rfx_object,
)
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DATA_RFXTRX_CONFIG
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the RFXtrx cover."""
if discovery_info is None:
return
async def async_setup_entry(
hass, config_entry, async_add_entities,
):
"""Set up config entry."""
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
device_ids = set()
def supported(event):
@ -48,8 +49,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
)
entities.append(entity)
add_entities(entities)
async_add_entities(entities)
@callback
def cover_update(event, device_id):
"""Handle cover updates from the RFXtrx gateway."""
if not supported(event):
@ -70,11 +72,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
entity = RfxtrxCover(
event.device, device_id, DEFAULT_SIGNAL_REPETITIONS, event=event
)
add_entities([entity])
async_add_entities([entity])
# Subscribe to main RFXtrx events
if discovery_info[CONF_AUTOMATIC_ADD]:
hass.helpers.dispatcher.dispatcher_connect(SIGNAL_EVENT, cover_update)
hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_EVENT, cover_update)
class RfxtrxCover(RfxtrxDevice, CoverEntity, RestoreEntity):
@ -123,6 +125,7 @@ class RfxtrxCover(RfxtrxDevice, CoverEntity, RestoreEntity):
elif event.values["Command"] in COMMAND_OFF_LIST:
self._state = False
@callback
def _handle_event(self, event, device_id):
"""Check if event applies to me and update."""
if device_id != self._device_id:
@ -130,4 +133,4 @@ class RfxtrxCover(RfxtrxDevice, CoverEntity, RestoreEntity):
self._apply_event(event)
self.schedule_update_ha_state()
self.async_write_ha_state()