8000 Add support for visual feedback for ZHA device reconfiguration by dmulcahey · Pull Request #48447 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for visual feedback for ZHA device reconfiguration #48447

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions homeassistant/components/zha/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,38 @@ async def websocket_remove_group_members(hass, connection, msg):
)
async def websocket_reconfigure_node(hass, connection, msg):
"""Reconfigure a ZHA nodes entities by its ieee address."""
zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
zha_gateway: ZhaGatewayType = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
ieee = msg[ATTR_IEEE]
device = zha_gateway.get_device(ieee)
device: ZhaDeviceType = zha_gateway.get_device(ieee)
ieee_str = str(device.ieee)
nwk_str = device.nwk.__repr__()

class DeviceLogFilterer(logging.Filter):
"""Log filterer that limits messages to the specified device."""

def filter(self, record):
message = record.getMessage()
return nwk_str in message or ieee_str in message

filterer = DeviceLogFilterer()

async def forward_messages(data):
"""Forward events to websocket."""
connection.send_message(websocket_api.event_message(msg["id"], data))

remove_dispatcher_function = async_dispatcher_connect(
hass, "zha_gateway_message", forward_messages
)

@callback
def async_cleanup() -> None:
"""Remove signal listener and turn off debug mode."""
zha_gateway.async_disable_debug_mode(filterer=filterer)
remove_dispatcher_function()

connection.subscriptions[msg["id"]] = async_cleanup
zha_gateway.async_enable_debug_mode(filterer=filterer)

_LOGGER.debug("Reconfiguring node with ieee_address: %s", ieee)
hass.async_create_task(device.async_configure())

Expand Down
9 changes: 7 additions & 2 deletions homeassistant/components/zha/core/gateway.py
648E
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,29 @@ def register_entity_reference(
)

@callback
def async_enable_debug_mode(self):
def async_enable_debug_mode(self, filterer=None):
"""Enable debug mode for ZHA."""
self._log_levels[DEBUG_LEVEL_ORIGINAL] = async_capture_log_levels()
async_set_logger_levels(DEBUG_LEVELS)
self._log_levels[DEBUG_LEVEL_CURRENT] = async_capture_log_levels()

if filterer:
self._log_relay_handler.addFilter(filterer)

for logger_name in DEBUG_RELAY_LOGGERS:
logging.getLogger(logger_name).addHandler(self._log_relay_handler)

self.debug_enabled = True

@callback
def async_disable_debug_mode(self):
def async_disable_debug_mode(self, filterer=None):
"""Disable debug mode for ZHA."""
async_set_logger_levels(self._log_levels[DEBUG_LEVEL_ORIGINAL])
self._log_levels[DEBUG_LEVEL_CURRENT] = async_capture_log_levels()
for logger_name in DEBUG_RELAY_LOGGERS:
logging.getLogger(logger_name).removeHandler(self._log_relay_handler)
if filterer:
self._log_relay_handler.removeFilter(filterer)
self.debug_enabled = False

@callback
Expand Down
0