Skip to content

Commit

Permalink
Much better camera support for FKB
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Jul 11, 2021
1 parent 87e939c commit 2ba8977
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ After restarting Home Assistant (and [clearing cache](https://github.com/thomasl

Be aware that keeping the camera on may make your device run hot and drain your battery.

The camera does not work well with Fully Kiosk Browser. If you're using FKB, use the built-in camera functionality instead. It's better in every way.
For Fully Kiosk Browser, the camera requires Motion Detection (PLUS) to be enabled, and will only appear for the first time once motion has been detected. It does not need to be enabled in the configuration, though.

### binary_sensor

Expand Down
2 changes: 1 addition & 1 deletion custom_components/browser_mod/browser_mod.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion custom_components/browser_mod/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

from .helpers import setup_platform, BrowserModEntity

import logging

PLATFORM = "camera"

LOGGER = logging.Logger(__name__)


async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModCamera)
Expand All @@ -30,7 +34,7 @@ def updated(self):
self.schedule_update_ha_state()

def camera_image(self):
return base64.b64decode(self.data.split(",")[1])
return base64.b64decode(self.data.split(",")[-1])

@property
def device_state_attributes(self):
Expand Down
12 changes: 9 additions & 3 deletions js/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ export const BrowserModCameraMixin = (C) =>

this._camera_framerate = 2;

window.addEventListener("click", () => this._video.play(), {
once: true,
});
window.addEventListener(
"click",
() => {
if (this._video.ended || this._video.paused) this._video.play();
},
{
once: true,
}
);
}

update_camera() {
Expand Down
15 changes: 15 additions & 0 deletions js/fullyKiosk.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,27 @@ export const FullyKioskMixin = (C) =>
});
}

startCamera() {
if (this._fullyCameraTimer !== undefined) return;
this._fullyCameraTimer = window.setInterval(() => {
this.sendUpdate({
camera: window.fully.getCamshotJpgBase64(),
});
}, 200);
}
stopCamera() {
window.clearInterval(this._fullyCameraTimer);
this._fullyCameraTimer = undefined;
}

fullyMotionTriggered() {
if (this._keepingAlive) return;
this._fullyMotion = true;
this.startCamera();
clearTimeout(this._motionTimeout);
this._motionTimeout = setTimeout(() => {
this._fullyMotion = false;
this.stopCamera();
this.fully_update();
}, 5000);
this.fully_update();
Expand Down
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class BrowserMod extends ext(BrowserModConnection, [
if (msg.name) {
this.entity_id = msg.name.toLowerCase();
}
if (msg.camera) {
if (msg.camera && !this.isFully) {
this.setup_camera();
}
this.config = { ...this.config, ...msg };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "browser_mod",
"private": true,
"version": "1.4.0",
"version": "1.5.0",
"description": "",
"scripts": {
"build": "rollup -c",
Expand Down

0 comments on commit 2ba8977

Please sign in to comment.