mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Fetch camera image via websocket connection (#1136)
* Fetch camera image via websocket connection Lint Cleanup * setProperties
This commit is contained in:
parent
9fc3d9d019
commit
06341edc49
@ -39,8 +39,11 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<img src='[[cameraFeedSrc]]' class='camera-feed' hidden$='[[!imageLoaded]]'
|
||||
on-load='imageLoadSuccess' on-error='imageLoadFail' alt='[[computeStateName(stateObj)]]'>
|
||||
<img
|
||||
src='[[cameraFeedSrc]]'
|
||||
class='camera-feed'
|
||||
hidden$='[[!imageLoaded]]'
|
||||
alt='[[computeStateName(stateObj)]]'>
|
||||
<div class='caption'>
|
||||
[[computeStateName(stateObj)]]
|
||||
<template is='dom-if' if='[[!imageLoaded]]'>
|
||||
@ -103,18 +106,20 @@
|
||||
}
|
||||
|
||||
updateCameraFeedSrc() {
|
||||
var attr = this.stateObj.attributes;
|
||||
var time = (new Date()).getTime();
|
||||
this.cameraFeedSrc = attr.entity_picture + '&time=' + time;
|
||||
}
|
||||
|
||||
imageLoadSuccess() {
|
||||
this.imageLoaded = true;
|
||||
}
|
||||
|
||||
imageLoadFail() {
|
||||
this.hass.connection.sendMessagePromise({
|
||||
type: 'camera_thumbnail',
|
||||
entity_id: this.stateObj.entity_id,
|
||||
}).then((resp) => {
|
||||
if (resp.success) {
|
||||
this.setProperties({
|
||||
imageLoaded: true,
|
||||
cameraFeedSrc: `data:${resp.result.content_type};base64, ${resp.result.content}`,
|
||||
});
|
||||
} else {
|
||||
this.imageLoaded = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
computeStateName(stateObj) {
|
||||
return window.hassUtil.computeStateName(stateObj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user