Move data on import in rfxtrx integration into ConfigEntry (#38022)
* Move all data imported from yaml to ConfigEntry * Revert changes that prevent updating yaml entry * Cleanup code around time conversionpull/38055/head
parent
60009ec2f9
commit
d9dba9142c
|
@ -29,7 +29,6 @@ from homeassistant.helpers.restore_state import RestoreEntity
|
|||
|
||||
from .const import (
|
||||
ATTR_EVENT,
|
||||
DATA_RFXTRX_CONFIG,
|
||||
DEVICE_PACKET_TYPE_LIGHTING4,
|
||||
EVENT_RFXTRX_EVENT,
|
||||
SERVICE_SEND,
|
||||
|
@ -105,7 +104,9 @@ DEVICE_DATA_SCHEMA = vol.Schema(
|
|||
{
|
||||
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
||||
vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean,
|
||||
vol.Optional(CONF_OFF_DELAY): vol.Any(cv.time_period, cv.positive_timedelta),
|
||||
vol.Optional(CONF_OFF_DELAY): vol.All(
|
||||
cv.time_period, cv.positive_timedelta, lambda value: value.total_seconds()
|
||||
),
|
||||
vol.Optional(CONF_DATA_BITS): cv.positive_int,
|
||||
vol.Optional(CONF_COMMAND_ON): cv.byte,
|
||||
vol.Optional(CONF_COMMAND_OFF): cv.byte,
|
||||
|
@ -135,21 +136,20 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
async def async_setup(hass, config):
|
||||
"""Set up the RFXtrx component."""
|
||||
if DOMAIN not in config:
|
||||
hass.data[DATA_RFXTRX_CONFIG] = BASE_SCHEMA({})
|
||||
return True
|
||||
|
||||
hass.data[DATA_RFXTRX_CONFIG] = config[DOMAIN]
|
||||
data = {
|
||||
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],
|
||||
}
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
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][CONF_DEBUG],
|
||||
},
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=data,
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
@ -169,11 +169,10 @@ async def async_setup_entry(hass, entry: config_entries.ConfigEntry):
|
|||
|
||||
def setup_internal(hass, config):
|
||||
"""Set up the RFXtrx component."""
|
||||
|
||||
# Setup some per device config
|
||||
device_events = set()
|
||||
device_bits = {}
|
||||
for event_code, event_config in hass.data[DATA_RFXTRX_CONFIG][CONF_DEVICES].items():
|
||||
for event_code, event_config in config[CONF_DEVICES].items():
|
||||
event = get_rfx_object(event_code)
|
||||
device_id = get_device_id(
|
||||
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
||||
|
|
|
@ -24,12 +24,7 @@ from . import (
|
|||
get_pt2262_cmd,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import (
|
||||
COMMAND_OFF_LIST,
|
||||
COMMAND_ON_LIST,
|
||||
DATA_RFXTRX_CONFIG,
|
||||
DEVICE_PACKET_TYPE_LIGHTING4,
|
||||
)
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DEVICE_PACKET_TYPE_LIGHTING4
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -43,7 +38,7 @@ async def async_setup_entry(
|
|||
device_ids = set()
|
||||
pt2262_devices = []
|
||||
|
||||
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
|
||||
discovery_info = config_entry.data
|
||||
|
||||
def supported(event):
|
||||
return isinstance(event, rfxtrxmod.ControlEvent)
|
||||
|
@ -197,5 +192,5 @@ class RfxtrxBinarySensor(RfxtrxEntity, BinarySensorEntity):
|
|||
self.async_write_ha_state()
|
||||
|
||||
self._delay_listener = evt.async_call_later(
|
||||
self.hass, self._off_delay.total_seconds(), off_delay_listener
|
||||
self.hass, self._off_delay, off_delay_listener
|
||||
)
|
||||
|
|
|
@ -16,7 +16,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
async def async_step_import(self, import_config=None):
|
||||
"""Handle the initial step."""
|
||||
|
||||
await self.async_set_unique_id(DOMAIN)
|
||||
self._abort_if_unique_id_configured(import_config)
|
||||
return self.async_create_entry(title="RFXTRX", data=import_config)
|
||||
|
|
|
@ -21,5 +21,4 @@ SERVICE_SEND = "send"
|
|||
|
||||
DEVICE_PACKET_TYPE_LIGHTING4 = 0x13
|
||||
|
||||
DATA_RFXTRX_CONFIG = "rfxtrx_config"
|
||||
EVENT_RFXTRX_EVENT = "rfxtrx_event"
|
||||
|
|
|
@ -14,7 +14,7 @@ from . import (
|
|||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DATA_RFXTRX_CONFIG
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -23,7 +23,7 @@ async def async_setup_entry(
|
|||
hass, config_entry, async_add_entities,
|
||||
):
|
||||
"""Set up config entry."""
|
||||
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
|
||||
discovery_info = config_entry.data
|
||||
device_ids = set()
|
||||
|
||||
def supported(event):
|
||||
|
|
|
@ -20,7 +20,7 @@ from . import (
|
|||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DATA_RFXTRX_CONFIG
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -31,7 +31,7 @@ async def async_setup_entry(
|
|||
hass, config_entry, async_add_entities,
|
||||
):
|
||||
"""Set up config entry."""
|
||||
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
|
||||
discovery_info = config_entry.data
|
||||
device_ids = set()
|
||||
|
||||
def supported(event):
|
||||
|
|
|
@ -20,7 +20,6 @@ from . import (
|
|||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import DATA_RFXTRX_CONFIG
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -57,7 +56,7 @@ async def async_setup_entry(
|
|||
hass, config_entry, async_add_entities,
|
||||
):
|
||||
"""Set up platform."""
|
||||
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
|
||||
discovery_info = config_entry.data
|
||||
data_ids = set()
|
||||
|
||||
def supported(event):
|
||||
|
|
|
@ -17,7 +17,7 @@ from . import (
|
|||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DATA_RFXTRX_CONFIG
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST
|
||||
|
||||
DATA_SWITCH = f"{DOMAIN}_switch"
|
||||
|
||||
|
@ -28,7 +28,7 @@ async def async_setup_entry(
|
|||
hass, config_entry, async_add_entities,
|
||||
):
|
||||
"""Set up config entry."""
|
||||
discovery_info = hass.data[DATA_RFXTRX_CONFIG]
|
||||
discovery_info = config_entry.data
|
||||
device_ids = set()
|
||||
|
||||
def supported(event):
|
||||
|
|
Loading…
Reference in New Issue