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>
|
</style>
|
||||||
|
|
||||||
<img src='[[cameraFeedSrc]]' class='camera-feed' hidden$='[[!imageLoaded]]'
|
<img
|
||||||
on-load='imageLoadSuccess' on-error='imageLoadFail' alt='[[computeStateName(stateObj)]]'>
|
src='[[cameraFeedSrc]]'
|
||||||
|
class='camera-feed'
|
||||||
|
hidden$='[[!imageLoaded]]'
|
||||||
|
alt='[[computeStateName(stateObj)]]'>
|
||||||
<div class='caption'>
|
<div class='caption'>
|
||||||
[[computeStateName(stateObj)]]
|
[[computeStateName(stateObj)]]
|
||||||
<template is='dom-if' if='[[!imageLoaded]]'>
|
<template is='dom-if' if='[[!imageLoaded]]'>
|
||||||
@ -103,18 +106,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateCameraFeedSrc() {
|
updateCameraFeedSrc() {
|
||||||
var attr = this.stateObj.attributes;
|
this.hass.connection.sendMessagePromise({
|
||||||
var time = (new Date()).getTime();
|
type: 'camera_thumbnail',
|
||||||
this.cameraFeedSrc = attr.entity_picture + '&time=' + time;
|
entity_id: this.stateObj.entity_id,
|
||||||
}
|
}).then((resp) => {
|
||||||
|
if (resp.success) {
|
||||||
imageLoadSuccess() {
|
this.setProperties({
|
||||||
this.imageLoaded = true;
|
imageLoaded: true,
|
||||||
}
|
cameraFeedSrc: `data:${resp.result.content_type};base64, ${resp.result.content}`,
|
||||||
|
});
|
||||||
imageLoadFail() {
|
} else {
|
||||||
this.imageLoaded = false;
|
this.imageLoaded = false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
computeStateName(stateObj) {
|
computeStateName(stateObj) {
|
||||||
return window.hassUtil.computeStateName(stateObj);
|
return window.hassUtil.computeStateName(stateObj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user