Implement config and option flow for rfxtrx integration (#39117)
* Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump pyRFXtrx to 0.26 and deprecate debug config key (#40679) * Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump version number * Remove debug key from connect * Remove debug option from config flow * Remove debug from tests * Fix event test * Add cv.deprecated * Fix test * Fix config schema * Add timeout on connection * Rework config schema * Fix schema...again * Prevent creation of duplicate device in rfxtrx option flow (#40656)
This commit is contained in:
1 parent
44e5ec58b0
commit
c5041b41c8
22 files changed
+2202
-363
No files matched your search
@@ -5,6 +5,7 @@ from collections import OrderedDict
|
||||
import logging
|
||||
|
||||
import RFXtrx as rfxtrxmod
|
||||
import async_timeout
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
@@ -33,11 +34,19 @@ from homeassistant.const import (
|
||||
VOLT,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .const import (
|
||||
ATTR_EVENT,
|
||||
CONF_AUTOMATIC_ADD,
|
||||
CONF_DATA_BITS,
|
||||
CONF_DEBUG,
|
||||
CONF_FIRE_EVENT,
|
||||
CONF_OFF_DELAY,
|
||||
CONF_REMOVE_DEVICE,
|
||||
CONF_SIGNAL_REPETITIONS,
|
||||
DEVICE_PACKET_TYPE_LIGHTING4,
|
||||
EVENT_RFXTRX_EVENT,
|
||||
SERVICE_SEND,
|
||||
@@ -47,12 +56,6 @@ DOMAIN = "rfxtrx"
|
||||
|
||||
DEFAULT_SIGNAL_REPETITIONS = 1
|
||||
|
||||
CONF_FIRE_EVENT = "fire_event"
|
||||
CONF_DATA_BITS = "data_bits"
|
||||
CONF_AUTOMATIC_ADD = "automatic_add"
|
||||
CONF_SIGNAL_REPETITIONS = "signal_repetitions"
|
||||
CONF_DEBUG = "debug"
|
||||
CONF_OFF_DELAY = "off_delay"
|
||||
SIGNAL_EVENT = f"{DOMAIN}_event"
|
||||
|
||||
DATA_TYPES = OrderedDict(
|
||||
@@ -126,10 +129,10 @@ DEVICE_DATA_SCHEMA = vol.Schema(
|
||||
|
||||
BASE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_DEBUG, default=False): cv.boolean,
|
||||
vol.Optional(CONF_DEBUG): cv.boolean,
|
||||
vol.Optional(CONF_AUTOMATIC_ADD, default=False): cv.boolean,
|
||||
vol.Optional(CONF_DEVICES, default={}): {cv.string: _ensure_device},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
DEVICE_SCHEMA = BASE_SCHEMA.extend({vol.Required(CONF_DEVICE): cv.string})
|
||||
@@ -139,7 +142,8 @@ PORT_SCHEMA = BASE_SCHEMA.extend(
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Any(DEVICE_SCHEMA, PORT_SCHEMA)}, extra=vol.ALLOW_EXTRA
|
||||
{DOMAIN: vol.All(cv.deprecated(CONF_DEBUG), vol.Any(DEVICE_SCHEMA, PORT_SCHEMA))},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
DOMAINS = ["switch", "sensor", "light", "binary_sensor", "cover"]
|
||||
@@ -154,7 +158,6 @@ async def async_setup(hass, config):
|
||||
CONF_HOST: config[DOMAIN].get(CONF_HOST),
|
||||
CONF_PORT: config[DOMAIN].get(CONF_PORT),
|
||||
CONF_DEVICE: config[DOMAIN].get(CONF_DEVICE),
|
||||
CONF_DEBUG: config[DOMAIN].get(CONF_DEBUG),
|
||||
CONF_AUTOMATIC_ADD: config[DOMAIN].get(CONF_AUTOMATIC_ADD),
|
||||
CONF_DEVICES: config[DOMAIN][CONF_DEVICES],
|
||||
}
|
||||
@@ -223,11 +226,10 @@ def _create_rfx(config):
|
||||
rfx = rfxtrxmod.Connect(
|
||||
(config[CONF_HOST], config[CONF_PORT]),
|
||||
None,
|
||||
debug=config[CONF_DEBUG],
|
||||
transport_protocol=rfxtrxmod.PyNetworkTransport,
|
||||
)
|
||||
else:
|
||||
rfx = rfxtrxmod.Connect(config[CONF_DEVICE], None, debug=config[CONF_DEBUG])
|
||||
rfx = rfxtrxmod.Connect(config[CONF_DEVICE], None)
|
||||
|
||||
return rfx
|
||||
|
||||
@@ -251,7 +253,11 @@ async def async_setup_internal(hass, entry: config_entries.ConfigEntry):
|
||||
config = entry.data
|
||||
|
||||
# Initialize library
|
||||
rfx_object = await hass.async_add_executor_job(_create_rfx, config)
|
||||
try:
|
||||
async with async_timeout.timeout(5):
|
||||
rfx_object = await hass.async_add_executor_job(_create_rfx, config)
|
||||
except asyncio.TimeoutError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
# Setup some per device config
|
||||
devices = _get_device_lookup(config[CONF_DEVICES])
|
||||
@@ -444,6 +450,12 @@ class RfxtrxEntity(RestoreEntity):
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
f"{DOMAIN}_{CONF_REMOVE_DEVICE}_{self._device_id}", self.async_remove
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed for a RFXtrx switch."""
|
||||
|
||||
Reference in new issue
Block a user