From 00ff712c0cd0d25d7970bc99a0eeef95a366f1a7 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:22:23 -0400 Subject: [PATCH 1/8] Log a warning instead of raising for unrecognized notification CCs --- test/model/test_node.py | 10 +++++++--- zwave_js_server/exceptions.py | 13 ------------- zwave_js_server/model/node/__init__.py | 7 +++++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/test/model/test_node.py b/test/model/test_node.py index 3916c013f..7c3c8c965 100644 --- a/test/model/test_node.py +++ b/test/model/test_node.py @@ -22,7 +22,6 @@ from zwave_js_server.exceptions import ( FailedCommand, NotFoundError, - NotificationHasUnsupportedCommandClass, UnwriteableValue, ) from zwave_js_server.model import endpoint as endpoint_pkg, node as node_pkg @@ -803,7 +802,11 @@ async def test_notification(lock_schlage_be469: node_pkg.Node): assert event.data["notification"].status == PowerLevelTestStatus.FAILED assert event.data["notification"].acknowledged_frames == 2 + +async def test_notification_unknown(lock_schlage_be469: node_pkg.Node, caplog): + """Test unrecognized command class notification events.""" # Validate that an unrecognized CC notification event raises Exception + node = lock_schlage_be469 event = Event( type="notification", data={ @@ -814,8 +817,9 @@ async def test_notification(lock_schlage_be469: node_pkg.Node): }, ) - with pytest.raises(NotificationHasUnsupportedCommandClass): - node.handle_notification(event) + node.handle_notification(event) + + assert "Unhandled notification command class" in caplog.text async def test_entry_control_notification(ring_keypad): diff --git a/zwave_js_server/exceptions.py b/zwave_js_server/exceptions.py index b6ee18d37..40acf10a5 100644 --- a/zwave_js_server/exceptions.py +++ b/zwave_js_server/exceptions.py @@ -157,16 +157,3 @@ def __init__(self, value: "Value", path: str) -> None: "upstream issue with the driver or missing support for this data in the " "library" ) - - -class NotificationHasUnsupportedCommandClass(BaseZwaveJSServerError): - """Exception raised when notification is received for an unsupported CC.""" - - def __init__(self, event: "Event", command_class: CommandClass) -> None: - """Initialize an invalid Command Class error.""" - self.event_data = event.data - self.command_class = command_class - super().__init__( - "Notification received with unsupported command class " - f"{command_class.name}: {event.data}" - ) diff --git a/zwave_js_server/model/node/__init__.py b/zwave_js_server/model/node/__init__.py index a4bf27d2a..676e8e40f 100644 --- a/zwave_js_server/model/node/__init__.py +++ b/zwave_js_server/model/node/__init__.py @@ -1,4 +1,5 @@ """Provide a model for the Z-Wave JS node.""" +import logging from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast from ...const import ( @@ -12,7 +13,6 @@ from ...exceptions import ( FailedCommand, NotFoundError, - NotificationHasUnsupportedCommandClass, UnparseableValue, UnwriteableValue, ) @@ -58,6 +58,9 @@ from ...client import Client +_LOGGER = logging.getLogger(__name__) + + class Node(EventBase): """Represent a Z-Wave JS node.""" @@ -789,7 +792,7 @@ def handle_notification(self, event: Event) -> None: self, cast(PowerLevelNotificationDataType, event.data) ) else: - raise NotificationHasUnsupportedCommandClass(event, command_class) + _LOGGER.warning("Unhandled notification command class: %s", command_class.name) def handle_firmware_update_progress(self, event: Event) -> None: """Process a node firmware update progress event.""" From e98939d802d409c90aa17cd6e22f4769ee95ade5 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:32:41 -0400 Subject: [PATCH 2/8] black --- zwave_js_server/model/node/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zwave_js_server/model/node/__init__.py b/zwave_js_server/model/node/__init__.py index 676e8e40f..bb6b6e544 100644 --- a/zwave_js_server/model/node/__init__.py +++ b/zwave_js_server/model/node/__init__.py @@ -792,7 +792,9 @@ def handle_notification(self, event: Event) -> None: self, cast(PowerLevelNotificationDataType, event.data) ) else: - _LOGGER.warning("Unhandled notification command class: %s", command_class.name) + _LOGGER.warning( + "Unhandled notification command class: %s", command_class.name + ) def handle_firmware_update_progress(self, event: Event) -> None: """Process a node firmware update progress event.""" From c02c9942e1379ef2e79678f5e51b6e254fc17aba Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:39:40 -0400 Subject: [PATCH 3/8] Remove unused import --- zwave_js_server/exceptions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/zwave_js_server/exceptions.py b/zwave_js_server/exceptions.py index 40acf10a5..367855e7f 100644 --- a/zwave_js_server/exceptions.py +++ b/zwave_js_server/exceptions.py @@ -4,7 +4,6 @@ from .const import CommandClass if TYPE_CHECKING: - from .event import Event from .model.value import Value From 60678f9477deb96cfdbcc8bf9f2b87d295704331 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:52:33 -0400 Subject: [PATCH 4/8] drop log message to info --- zwave_js_server/model/node/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zwave_js_server/model/node/__init__.py b/zwave_js_server/model/node/__init__.py index bb6b6e544..30473829c 100644 --- a/zwave_js_server/model/node/__init__.py +++ b/zwave_js_server/model/node/__init__.py @@ -792,7 +792,7 @@ def handle_notification(self, event: Event) -> None: self, cast(PowerLevelNotificationDataType, event.data) ) else: - _LOGGER.warning( + _LOGGER.info( "Unhandled notification command class: %s", command_class.name ) From 4c690bf4a963cb40b3020028423b02cceda341cd Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:52:47 -0400 Subject: [PATCH 5/8] black --- zwave_js_server/model/node/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zwave_js_server/model/node/__init__.py b/zwave_js_server/model/node/__init__.py index 30473829c..40e08c758 100644 --- a/zwave_js_server/model/node/__init__.py +++ b/zwave_js_server/model/node/__init__.py @@ -792,9 +792,7 @@ def handle_notification(self, event: Event) -> None: self, cast(PowerLevelNotificationDataType, event.data) ) else: - _LOGGER.info( - "Unhandled notification command class: %s", command_class.name - ) + _LOGGER.info("Unhandled notification command class: %s", command_class.name) def handle_firmware_update_progress(self, event: Event) -> None: """Process a node firmware update progress event.""" From 9eb10f3c1bf67f6a02c2318850847ce040b70d27 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 01:02:23 -0400 Subject: [PATCH 6/8] Fix test --- test/model/test_node.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/model/test_node.py b/test/model/test_node.py index 7c3c8c965..ea3a3f371 100644 --- a/test/model/test_node.py +++ b/test/model/test_node.py @@ -1,5 +1,6 @@ """Test the node model.""" import json +import logging from copy import deepcopy from unittest.mock import patch @@ -819,7 +820,7 @@ async def test_notification_unknown(lock_schlage_be469: node_pkg.Node, caplog): node.handle_notification(event) - assert "Unhandled notification command class" in caplog.text + assert "notification" not in event.data async def test_entry_control_notification(ring_keypad): From eeeac5937e8f47320bde74e1d98d6ea3e5b45868 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 01:07:11 -0400 Subject: [PATCH 7/8] Update zwave_js_server/model/node/__init__.py Co-authored-by: Martin Hjelmare --- zwave_js_server/model/node/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zwave_js_server/model/node/__init__.py b/zwave_js_server/model/node/__init__.py index 40e08c758..7c5281303 100644 --- a/zwave_js_server/model/node/__init__.py +++ b/zwave_js_server/model/node/__init__.py @@ -58,7 +58,7 @@ from ...client import Client -_LOGGER = logging.getLogger(__name__) +_LOGGER = logging.getLogger(__package__) class Node(EventBase): From 7be3c228e7523926a89171d34dff8a955fb1a90c Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 21 Apr 2022 01:09:21 -0400 Subject: [PATCH 8/8] remove unused import --- test/model/test_node.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/model/test_node.py b/test/model/test_node.py index ea3a3f371..c30d522e6 100644 --- a/test/model/test_node.py +++ b/test/model/test_node.py @@ -1,6 +1,5 @@ """Test the node model.""" import json -import logging from copy import deepcopy from unittest.mock import patch