From 332c91252cd2051927d7f7a4ba46cc0fb7665bb1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 12 Apr 2022 23:44:14 +0200 Subject: [PATCH] zwave.mqtt.status renamed to controller_status, while status should return the current state of the values --- .../src/components/panels/Zwave/Zwave.vue | 2 +- platypush/plugins/zwave/mqtt/__init__.py | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/panels/Zwave/Zwave.vue b/platypush/backend/http/webapp/src/components/panels/Zwave/Zwave.vue index e0466ba98..516e8687b 100644 --- a/platypush/backend/http/webapp/src/components/panels/Zwave/Zwave.vue +++ b/platypush/backend/http/webapp/src/components/panels/Zwave/Zwave.vue @@ -356,7 +356,7 @@ export default { async refreshStatus() { this.loading.status = true try { - this.status = await this.zrequest('status') + this.status = await this.zrequest('controller_status') } finally { this.loading.status = false } diff --git a/platypush/plugins/zwave/mqtt/__init__.py b/platypush/plugins/zwave/mqtt/__init__.py index 4c1bbab14..642a7dbe1 100644 --- a/platypush/plugins/zwave/mqtt/__init__.py +++ b/platypush/plugins/zwave/mqtt/__init__.py @@ -496,7 +496,7 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): def _filter_values( self, - command_classes: Iterable[str], + command_classes: Optional[Iterable[str]] = None, filter_callback: Optional[Callable[[dict], bool]] = None, node_id: Optional[int] = None, node_name: Optional[str] = None, @@ -509,16 +509,18 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): ) command_classes = { - command_class_by_name[command_name] for command_name in command_classes + command_class_by_name[command_name] + for command_name in (command_classes or []) } values = {} for node in nodes: for value in node.get('values', {}).values(): - if value.get('command_class') not in command_classes or ( - filter_callback and not filter_callback(value) - ): + if ( + command_classes + and value.get('command_class') not in command_classes + ) or (filter_callback and not filter_callback(value)): continue value_id = value['id_on_network'] @@ -570,15 +572,24 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): @action def status(self, **kwargs) -> Dict[str, Any]: + """ + Get the current status of the Z-Wave values. + + :param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish`` + (default: query the default configured device). + """ + return self._filter_values(**kwargs) + + @action + def controller_status(self, **kwargs) -> Dict[str, Any]: """ Get the status of the controller. :param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish`` (default: query the default configured device). - :return: dict with the following fields: ``device`` and ``state``. """ msg_queue = queue.Queue() - topic = f'{self.topic_prefix}/Controller/status' + topic = f'{self.topic_prefix}/driver/status' client = self._get_client(**kwargs) def on_message(_, __, msg): @@ -606,9 +617,7 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): client.loop_stop() return { - 'device': status['nodeId'], - 'state': status['status'], - 'stats': {}, + 'state': status, } @action