From 47f8520f3ba0482c70310e3aeb433c68afe6c3aa Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 24 Apr 2022 22:18:29 +0200 Subject: [PATCH] Added support for description/read_only/write_only on entity level --- .../http/webapp/src/components/panels/Entities/Switch.vue | 2 +- platypush/entities/_base.py | 4 ++++ platypush/plugins/switchbot/__init__.py | 1 + platypush/plugins/switchbot/bluetooth/__init__.py | 1 + platypush/plugins/zigbee/mqtt/__init__.py | 2 +- platypush/plugins/zwave/mqtt/__init__.py | 6 +++--- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue index e5701a90b..2a9d2cd29 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Switch.vue @@ -6,7 +6,7 @@
+ @click.stop :disabled="loading || value.is_read_only" />
diff --git a/platypush/entities/_base.py b/platypush/entities/_base.py index fe4ec2c6f..0f5195727 100644 --- a/platypush/entities/_base.py +++ b/platypush/entities/_base.py @@ -5,6 +5,7 @@ from typing import Mapping, Type, Tuple, Any import pkgutil from sqlalchemy import ( + Boolean, Column, Index, Integer, @@ -32,10 +33,13 @@ class Entity(Base): id = Column(Integer, autoincrement=True, primary_key=True) external_id = Column(String, nullable=True) name = Column(String, nullable=False, index=True) + description = Column(String) type = Column(String, nullable=False, index=True) plugin = Column(String, nullable=False) data = Column(JSON, default=dict) meta = Column(JSON, default=dict) + is_read_only = Column(Boolean, default=False) + is_write_only = Column(Boolean, default=False) created_at = Column( DateTime(timezone=False), default=datetime.utcnow(), nullable=False ) diff --git a/platypush/plugins/switchbot/__init__.py b/platypush/plugins/switchbot/__init__.py index 3b91c9114..8d7b0e602 100644 --- a/platypush/plugins/switchbot/__init__.py +++ b/platypush/plugins/switchbot/__init__.py @@ -114,6 +114,7 @@ class SwitchbotPlugin(SwitchPlugin): id=dev["id"], name=dev["name"], state=dev.get("on"), + is_write_only=True, data={ "device_type": dev.get("device_type"), "is_virtual": dev.get("is_virtual", False), diff --git a/platypush/plugins/switchbot/bluetooth/__init__.py b/platypush/plugins/switchbot/bluetooth/__init__.py index 5ab98ab6f..5da12b3d9 100644 --- a/platypush/plugins/switchbot/bluetooth/__init__.py +++ b/platypush/plugins/switchbot/bluetooth/__init__.py @@ -184,6 +184,7 @@ class SwitchbotBluetoothPlugin( # lgtm [py/missing-call-to-init] id=addr, name=name, state=False, + is_write_only=True, ) for addr, name in devices.items() ] diff --git a/platypush/plugins/zigbee/mqtt/__init__.py b/platypush/plugins/zigbee/mqtt/__init__.py index 0aa8f2af5..de0e189b4 100644 --- a/platypush/plugins/zigbee/mqtt/__init__.py +++ b/platypush/plugins/zigbee/mqtt/__init__.py @@ -178,7 +178,6 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in "model": dev_def.get("model"), "vendor": dev_def.get("vendor"), "supported": dev.get("supported"), - "description": dev_def.get("description"), } switch_info = self._get_switch_meta(dev) @@ -187,6 +186,7 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in id=dev['ieee_address'], name=dev.get('friendly_name'), state=dev.get('state', {}).get('state') == 'ON', + description=dev_def.get("description"), data=dev_info, ) diff --git a/platypush/plugins/zwave/mqtt/__init__.py b/platypush/plugins/zwave/mqtt/__init__.py index 642a7dbe1..49eb21751 100644 --- a/platypush/plugins/zwave/mqtt/__init__.py +++ b/platypush/plugins/zwave/mqtt/__init__.py @@ -479,10 +479,10 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): value_name=value["label"], ), state=value['data'], + description=value.get('help'), + is_read_only=value.get('is_read_only'), + is_write_only=value.get('is_write_only'), data={ - 'help': value.get('help'), - 'is_read_only': value.get('is_read_only'), - 'is_write_only': value.get('is_write_only'), 'label': value.get('label'), 'node_id': value.get('node_id'), },