Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Custom component for lovelace to be used as a panel for viewing security cameras
| cameras | list | _See camera section below_ | **Required**
| thumb_interval | number | Update interval for thumbnails in seconds (_min_ 0.5) | 10
| update_interval | number | Update interval for main image in seconds (_min_ 0.5) | 1
| focus_interval | number | Update interval for automatic transition to next camera in seconds (_min_ 10) | 0
| focus_motion | boolean | Switch to camera when motion detected | true

### Camera configuration
Expand Down
26 changes: 23 additions & 3 deletions surveillance-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class SurveillanceCard extends LitElement {
selectedCamera: { type: Object },
focusOnMotion: { type: Boolean },
thumbInterval: { type: Number },
updateInterval: { type: Number }
updateInterval: { type: Number },
focusInterval: { type: Number }
};
}

Expand Down Expand Up @@ -68,6 +69,7 @@ class SurveillanceCard extends LitElement {
this.focusOnMotion = config.focus_motion !== false;
this.thumbInterval = (config.thumb_interval || 10.0) * 1000;
this.updateInterval = config.update_interval || 1.0;
this.focusInterval = (config.focus_interval || 0) * 1000;

const now = Date.now();
this.cameras = config.cameras.map((camera) => {
Expand Down Expand Up @@ -127,7 +129,11 @@ class SurveillanceCard extends LitElement {
this.cameras = [...this.cameras];
}

_updateSelectedCamera(camera) {
_updateSelectedCamera(camera, autochanged = false) {
if (!autochanged) {
clearTimeout(this.autochangeTimer);
}

if (!camera || !camera.access_token) {
let availableCameras = this.cameras.filter((c) => c.access_token && c.has_motion);
availableCameras.sort(this._cameraSortComparer);
Expand All @@ -137,6 +143,21 @@ class SurveillanceCard extends LitElement {
if (this.selectedCamera !== camera) {
this.selectedCamera = camera;
}

if (this.focusInterval >= 10000) {
this.autochangeTimer = setTimeout(() => { this._nextCamera() }, this.focusInterval);
}
}

_nextCamera() {
let current_index = this.cameras.indexOf(this.selectedCamera);
let next_index = current_index + 1;

if (next_index >= this.cameras.length) {
next_index = 0;
}

this._updateSelectedCamera(this.cameras[next_index], true);
}

_cameraSortComparer(cameraA, cameraB) {
Expand All @@ -162,7 +183,6 @@ class SurveillanceCard extends LitElement {
width: 100%;
display: flex;
align-items: stretch;
position: absolute;
}

.thumbs {
Expand Down