Support for external_url and image_url on entities

This commit is contained in:
Fabio Manganiello 2023-01-15 20:01:47 +01:00
parent 2cc5e3f726
commit 9a5e2899e8
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 60 additions and 0 deletions

View file

@ -76,6 +76,20 @@
<div class="value" v-text="entity.description" />
</div>
<div class="table-row" v-if="entity.external_url">
<div class="title">External URL</div>
<div class="value url">
<a :href="entity.external_url" target="_blank" :text="entity.external_url" />
</div>
</div>
<div class="table-row" v-if="entity.image_url">
<div class="title">Image</div>
<div class="value">
<img class="entity-image" :src="entity.image_url">
</div>
</div>
<div v-for="value, attr in entity.data || {}" :key="attr">
<div class="table-row" v-if="value != null">
<div class="title" v-text="prettify(attr)" />
@ -314,5 +328,15 @@ export default {
}
}
}
.value {
&.url {
text-align: right;
}
.entity-image {
max-height: 5em;
}
}
}
</style>

View file

@ -54,6 +54,9 @@ if 'entity' not in Base.metadata:
is_write_only = Column(Boolean, default=False)
is_query_disabled = Column(Boolean, default=False)
is_configuration = Column(Boolean, default=False)
external_url = Column(String)
image_url = Column(String)
created_at = Column(
DateTime(timezone=False), default=datetime.utcnow(), nullable=False
)

View file

@ -292,6 +292,8 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init]
id=dev['ieee_address'],
name=dev.get('friendly_name'),
description=dev_def.get('description'),
external_url=self._get_device_url(dev),
image_url=self._get_image_url(dev),
reachable=reachable,
)
@ -303,6 +305,22 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init]
return super().transform_entities(compatible_entities) # type: ignore
@staticmethod
def _get_device_url(device_info: dict) -> Optional[str]:
model = device_info.get('definition', {}).get('model')
if not model:
return
return f'https://www.zigbee2mqtt.io/devices/{model}.html'
@staticmethod
def _get_image_url(device_info: dict) -> Optional[str]:
model = device_info.get('definition', {}).get('model')
if not model:
return
return f'https://www.zigbee2mqtt.io/images/devices/{model}.jpg'
def _get_network_info(self, **kwargs) -> dict:
self.logger.info('Fetching Zigbee network information')
client = None

View file

@ -767,6 +767,7 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
parent = parent_entities[node_id] = Device(
id=node['device_id'],
name=node.get('name'),
external_url=self._build_external_url(node),
reachable=(
node.get('is_available', False) and node.get('is_ready', False)
),
@ -777,6 +778,20 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
entity.parent = parent
entity.reachable = parent.reachable
@staticmethod
def _build_external_url(node: dict) -> Optional[str]:
manufacturer_id = node.get('manufacturer_id')
product_id = node.get('product_id')
product_type = node.get('product_type')
firmware_version = node.get('firmware_version', '0.0')
if not (manufacturer_id and product_id and product_type):
return
return (
'https://devices.zwave-js.io/?jumpTo='
f'{manufacturer_id}:{product_type}:{product_id}:{firmware_version}'
)
@classmethod
def _merge_current_and_target_values(cls, values: Iterable[dict]) -> List[dict]:
values_by_id = OrderedDict({v.get('id'): v for v in values})