Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter rfxtrx configure devices option flow on existing config entry #40975

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/rfxtrx/__init__.py
Expand Up @@ -2,6 +2,7 @@
import asyncio
import binascii
from collections import OrderedDict
import copy
import logging

import RFXtrx as rfxtrxmod
Expand Down Expand Up @@ -303,6 +304,7 @@ def _add_device(event, device_id):
config[CONF_DEVICE_ID] = device_id

data = entry.data.copy()
data[CONF_DEVICES] = copy.deepcopy(entry.data[CONF_DEVICES])
RobBie1221 marked this conversation as resolved.
Show resolved Hide resolved
event_code = binascii.hexlify(event.data).decode("ASCII")
data[CONF_DEVICES][event_code] = config
hass.config_entries.async_update_entry(entry=entry, data=data)
Expand Down
20 changes: 16 additions & 4 deletions homeassistant/components/rfxtrx/config_flow.py
Expand Up @@ -109,7 +109,8 @@ async def async_step_prompt_options(self, user_input=None):
f"{DOMAIN}_{CONF_REMOVE_DEVICE}_{device_id}"
)
self._device_registry.async_remove_device(entry_id)
devices[event_code] = None
if event_code is not None:
devices[event_code] = None
RobBie1221 marked this conversation as resolved.
Show resolved Hide resolved

self.update_config_data(
global_options=self._global_options, devices=devices
Expand Down Expand Up @@ -142,19 +143,25 @@ async def async_step_prompt_options(self, user_input=None):
self._device_registry = device_registry
self._device_entries = device_entries

devices = {
remove_devices = {
entry.id: entry.name_by_user if entry.name_by_user else entry.name
for entry in device_entries
}

configure_devices = {
entry.id: entry.name_by_user if entry.name_by_user else entry.name
for entry in device_entries
if self._get_device_event_code(entry.id) is not None
}

options = {
vol.Optional(
CONF_AUTOMATIC_ADD,
default=self._config_entry.data[CONF_AUTOMATIC_ADD],
): bool,
vol.Optional(CONF_EVENT_CODE): str,
vol.Optional(CONF_DEVICE): vol.In(devices),
vol.Optional(CONF_REMOVE_DEVICE): cv.multi_select(devices),
vol.Optional(CONF_DEVICE): vol.In(configure_devices),
vol.Optional(CONF_REMOVE_DEVICE): cv.multi_select(remove_devices),
}

return self.async_show_form(
Expand Down Expand Up @@ -366,6 +373,11 @@ def _can_replace_device(self, entry_id):

return False

def _get_device_event_code(self, entry_id):
data = self._get_device_data(entry_id)

return data[CONF_EVENT_CODE]

def _get_device_data(self, entry_id):
"""Get event code based on device identifier."""
event_code = None
Expand Down