Added support for description/read_only/write_only on entity level

This commit is contained in:
Fabio Manganiello 2022-04-24 22:18:29 +02:00
parent d261b9bb9b
commit 47f8520f3b
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
6 changed files with 11 additions and 5 deletions

View File

@ -6,7 +6,7 @@
<div class="col-2 switch pull-right"> <div class="col-2 switch pull-right">
<ToggleSwitch :value="value.state" @input="toggle" <ToggleSwitch :value="value.state" @input="toggle"
@click.stop :disabled="loading" /> @click.stop :disabled="loading || value.is_read_only" />
</div> </div>
</div> </div>
</template> </template>

View File

@ -5,6 +5,7 @@ from typing import Mapping, Type, Tuple, Any
import pkgutil import pkgutil
from sqlalchemy import ( from sqlalchemy import (
Boolean,
Column, Column,
Index, Index,
Integer, Integer,
@ -32,10 +33,13 @@ class Entity(Base):
id = Column(Integer, autoincrement=True, primary_key=True) id = Column(Integer, autoincrement=True, primary_key=True)
external_id = Column(String, nullable=True) external_id = Column(String, nullable=True)
name = Column(String, nullable=False, index=True) name = Column(String, nullable=False, index=True)
description = Column(String)
type = Column(String, nullable=False, index=True) type = Column(String, nullable=False, index=True)
plugin = Column(String, nullable=False) plugin = Column(String, nullable=False)
data = Column(JSON, default=dict) data = Column(JSON, default=dict)
meta = 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( created_at = Column(
DateTime(timezone=False), default=datetime.utcnow(), nullable=False DateTime(timezone=False), default=datetime.utcnow(), nullable=False
) )

View File

@ -114,6 +114,7 @@ class SwitchbotPlugin(SwitchPlugin):
id=dev["id"], id=dev["id"],
name=dev["name"], name=dev["name"],
state=dev.get("on"), state=dev.get("on"),
is_write_only=True,
data={ data={
"device_type": dev.get("device_type"), "device_type": dev.get("device_type"),
"is_virtual": dev.get("is_virtual", False), "is_virtual": dev.get("is_virtual", False),

View File

@ -184,6 +184,7 @@ class SwitchbotBluetoothPlugin( # lgtm [py/missing-call-to-init]
id=addr, id=addr,
name=name, name=name,
state=False, state=False,
is_write_only=True,
) )
for addr, name in devices.items() for addr, name in devices.items()
] ]

View File

@ -178,7 +178,6 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in
"model": dev_def.get("model"), "model": dev_def.get("model"),
"vendor": dev_def.get("vendor"), "vendor": dev_def.get("vendor"),
"supported": dev.get("supported"), "supported": dev.get("supported"),
"description": dev_def.get("description"),
} }
switch_info = self._get_switch_meta(dev) 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'], id=dev['ieee_address'],
name=dev.get('friendly_name'), name=dev.get('friendly_name'),
state=dev.get('state', {}).get('state') == 'ON', state=dev.get('state', {}).get('state') == 'ON',
description=dev_def.get("description"),
data=dev_info, data=dev_info,
) )

View File

@ -479,10 +479,10 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
value_name=value["label"], value_name=value["label"],
), ),
state=value['data'], state=value['data'],
description=value.get('help'),
is_read_only=value.get('is_read_only'),
is_write_only=value.get('is_write_only'),
data={ 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'), 'label': value.get('label'),
'node_id': value.get('node_id'), 'node_id': value.get('node_id'),
}, },