Restructuring complete. Timeouts on popups. Fully Kiosk compatibility.
This commit is contained in:
parent
fdc509f402
commit
409a2fbf1e
71
README.md
71
README.md
@ -7,10 +7,11 @@ A Home Assistant integration to turn your browser into a controllable entity - a
|
||||
|
||||
## Example uses
|
||||
|
||||
- Make the camera feed from your front door pop up on the tablett in your kitchen when someone rings the doorbell.
|
||||
- Make the camera feed from your front door pop up on the tablet in your kitchen when someone rings the doorbell.
|
||||
- Have a message pop up on every screen in the house when it's bedtime.
|
||||
- Make the browser on your workstation switch to a specific tab when the kitchen light is on after midnight
|
||||
- Play a TTS message on your work computer when the traffic sensor tells you it's time to go home.
|
||||
- Display a full screen clock on your screen if no one's touched it for five minutes
|
||||
|
||||
# Installation instructions
|
||||
|
||||
@ -49,38 +50,73 @@ Since the deviceID can be a bit hard to remember for devices you use often, you
|
||||
browser_mod:
|
||||
devices:
|
||||
99980b13-dabc9563:
|
||||
name: Arrakis
|
||||
name: arrakis
|
||||
d2fc860c-16379d23:
|
||||
name: dashboard
|
||||
```
|
||||
This binds the *aliases* `Arrakis` to `99980b13-dabc9563` and `dashboard` to `d2fc860c-16379d23`.
|
||||
This binds the *aliases* `arrakis` to `99980b13-dabc9563` and `dashboard` to `d2fc860c-16379d23`.
|
||||
|
||||
Note: Aliases must be unique.
|
||||
|
||||
## media\_player
|
||||
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create a new `media_player` device.
|
||||
## Entities
|
||||
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three or four new devices.
|
||||
|
||||
Any sound played on this media player will be played by the *device*.
|
||||
- `sensor.<device>`
|
||||
- `media_player.<device>`
|
||||
- `light.<device>`
|
||||
- If you're using Fully Kiosk Browser `binary_sensor.<device>`
|
||||
|
||||
The `media_player` entity also has some extra attributes presenting the current state of the *device*.
|
||||
`<device>` here will be the `deviceID` of the *device* but with the dash (`-`) replaced by an underscore (`_`). If you've defined an alias, it will be that instead.
|
||||
|
||||
E.g:
|
||||
Connecting your phone with `deviceID: ded3b4dc-abedd098` will create the entities `sensor.ded3b4dc_abedd098`, `media_player.ded3b4dc_abedd098` and `light.ded3b4dc_abedd098`.
|
||||
Connecting with the computer named `Arrakis` above with `deviceID: 99980b13-dabc9563` will create the entities `sensor.arrakis`, `media_player.arrakis` and `light.arrakis`.
|
||||
|
||||
### sensor
|
||||
|
||||
The `sensor` will display the number of connected views (tabs/windows) of the device. Note that using multiple view isn't really recommended, and any action targeting a device will happen in the last loaded view.
|
||||
|
||||
The sensor also has the following attributes:
|
||||
|
||||
| attribute | content |
|
||||
| --- | --- |
|
||||
| `type` | `browser_mod` |
|
||||
| `last_seen` | The time when the *device* was last seen |
|
||||
| `deviceID` | The deviceID of the *device*. |
|
||||
| `path` | The currently displayed path on the *device*. |
|
||||
| `visibility` | Whether the frontend is currently visible on the *device*. |
|
||||
| `userAgent` | The User Agent of the associated browser. |
|
||||
| `currentUser` | The user currently logged in on the *device*. |
|
||||
| `blackout` | Whether the view on the *device* is currently blacked out (see below). |
|
||||
| `fullyKiosk` | True if the *device* is a Fully Kiosk browser. Undefined otherwise. |
|
||||
| `width` | The current width of the browser window in pixels. |
|
||||
| `height` | The current height of the browser window in pixels. |
|
||||
|
||||
**NOTE: Because apple is apple; on iOS you need to touch the screen once after loading the frontend before any playback will work.**
|
||||
### media\_player
|
||||
|
||||
The `media_player` can be used to play sounds on the *device*.
|
||||
|
||||
**NOTE: Because Apple is Apple; on iOS you need to touch the screen once after loading the frontend before any playback will work.**
|
||||
|
||||
### light
|
||||
|
||||
The `light` can be used to blackout the screen.
|
||||
For Fully Kiosk Browser, the screen will actually turn off.
|
||||
For other browsers, the interface will just be covered with black (the screen is still on, will have a visible glow in the dark, and you won't save any battery).
|
||||
|
||||
### binary\_sensor
|
||||
|
||||
The `binary_sensor` will only be available for Fully Kiosk Browser PRO *devices*.
|
||||
It's state will be the state of the camera motion detector of the *device* (5 second cooldown).
|
||||
|
||||
## `browser_mod.command` service
|
||||
|
||||
Call the `browser_mod.command` service to control your *device* in various ways.
|
||||
|
||||
All service calls have two parameters in common, `command` which is the command to execute, and `deviceID` which is a list of *devices* to execute the command on. If `deviceID` is omitted, the command will be executed on **all** currently connected *devices*.
|
||||
All service calls have two parameters in common, `command` which is the command to execute, and `deviceID` which is a list of *devices* to execute the command on. If `deviceID` is omitted, the command will be executed on **all** currently connected *devices*. `deviceID` may also contain aliases.
|
||||
|
||||
`deviceID` may also contain aliases, and there's a special alias named `this` which will evaluate to the *device* from which a command was initiated (if from the frontend).
|
||||
There is a special function that will replace the special alias `this` with the current deviceID in the list `deviceID` for any service call from the frontend. In the examples below it will be shown used for the `browser_mod.command` service, but it also works e.g for calling scripts from the frontend.
|
||||
|
||||
All examples below are given in the syntax used for calling them from lovelace via e.g. an entity-button card with `tap_action:` set to `call-service`. If you call the service from a script or an automation, the syntax will be slightly different.
|
||||
|
||||
### debug
|
||||
|
||||
@ -90,7 +126,7 @@ service_data:
|
||||
command: debug
|
||||
```
|
||||
|
||||
Display a popup with the deviceID *and* a javascript allert with the deviceID on all connected *devices*.
|
||||
Display a popup with the deviceID *and* a javascript alert with the deviceID on all connected *devices*.
|
||||
|
||||
### set-theme
|
||||
|
||||
@ -153,8 +189,9 @@ will display the specified `entities` card as a popup on the current device.
|
||||

|
||||
|
||||
The optional parameter `large: true` will make the popup wider.
|
||||
The optional parameter `style:` will apply css style options to the popup.
|
||||
The optional parameter `style:` will apply CSS style options to the popup.
|
||||
The optional parameter `auto_close: true` will make the popup close automatically when the mouse is moved or a key is pressed on the keyboard. This also removes the header bar.
|
||||
The optional parameter `time:` (only useable if `auto_close: true` is also set) will turn the popup into a "screensaver". See the `blackout` command below.
|
||||
|
||||
Ex:
|
||||
```yaml
|
||||
@ -185,6 +222,8 @@ service_data:
|
||||
Will cover the entire window (or screen if in full screen mode) with black.
|
||||
Moving the mouse, touching the screen or pressing any key will restore the view.
|
||||
|
||||
The optional parameter `time:` will make the blackout turn on automatically after the specified number of seconds. It works kind of like a screensaver and will keep turning on until `blackout` is called again with `time: -1`.
|
||||
|
||||
Note: This will *not* turn off your screen backlight. Most screens will still emit light in a dark room.
|
||||
|
||||
### no-blackout
|
||||
@ -224,7 +263,7 @@ The player card also displays the `entityID`. Click it to select, so you can cop
|
||||
# Fully Kiosk Browser
|
||||
If you are using a device running [Fully Kiosk Browser](https://www.ozerov.de/fully-kiosk-browser/) (PLUS version only) you will have access to a few more functions.
|
||||
|
||||
First of all the commands `blackout` and `no-blackout` will controll the devices screen directly.
|
||||
First of all the commands `blackout` and `no-blackout` will control the devices screen directly.
|
||||
`no-blackout` also has an optional parameter `brightness` that can set the screen brightness between 0 and 255.
|
||||
|
||||
Second, there are a few more attributes available
|
||||
@ -257,7 +296,7 @@ This actually means it pretty much replaces `popup-card` as well.
|
||||
- This works even if the currently logged in user is not in the admin group.
|
||||
|
||||
### Does this replace lovelace-fullykiosk
|
||||
It will, eventually.
|
||||
Yes. You need the paid version, btw.
|
||||
|
||||
### Can the deviceID be used to track me across the internet
|
||||
|
||||
@ -269,7 +308,7 @@ Some of [my lovelace plugins](https://github.com/thomasloven/hass-config/wiki/My
|
||||
|
||||
### How do I run commands from /dev-service?
|
||||
|
||||
`/dev-service` requires json-formated service data. There's an explanation on the differences between yaml and json [here](http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/).
|
||||
`/dev-service` requires json-formatted service data. There's an explanation on the differences between yaml and json [here](http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/).
|
||||
|
||||
---
|
||||
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
|
||||
|
@ -26,6 +26,7 @@ async def async_setup(hass, config):
|
||||
|
||||
await hass.helpers.discovery.async_load_platform("media_player", DOMAIN, {}, config)
|
||||
await hass.helpers.discovery.async_load_platform("sensor", DOMAIN, {}, config)
|
||||
await hass.helpers.discovery.async_load_platform("binary_sensor", DOMAIN, {}, config)
|
||||
await hass.helpers.discovery.async_load_platform("light", DOMAIN, {}, config)
|
||||
|
||||
await setup_connection(hass, config)
|
||||
|
50
custom_components/browser_mod/binary_sensor.py
Normal file
50
custom_components/browser_mod/binary_sensor.py
Normal file
@ -0,0 +1,50 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF
|
||||
from homeassistant.components.binary_sensor import DEVICE_CLASS_MOTION
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
PLATFORM = 'binary_sensor'
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModSensor)
|
||||
|
||||
class BrowserModSensor(BrowserModEntity):
|
||||
domain = PLATFORM
|
||||
|
||||
def __init__(self, hass, connection, deviceID, alias=None):
|
||||
super().__init__(hass, connection, deviceID, alias)
|
||||
self.last_seen = None
|
||||
|
||||
def updated(self):
|
||||
self.last_seen = datetime.now()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if not self.connection.connection:
|
||||
return STATE_UNAVAILABLE
|
||||
if self.data.get('motion', False):
|
||||
return STATE_ON
|
||||
return STATE_OFF
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return not self.data.get('motion', False)
|
||||
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
return DEVICE_CLASS_MOTION
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"last_seen": self.last_seen,
|
||||
ATTR_BATTERY_LEVEL: self.data.get('battery', None),
|
||||
ATTR_BATTERY_CHARGING: self.data.get('charging', None),
|
||||
**self.data
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -10,23 +10,18 @@ from .helpers import get_devices, create_entity
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def setup_connection(hass, config):
|
||||
_LOGGER.error("--------------------")
|
||||
_LOGGER.error("Setting up BM connection")
|
||||
|
||||
@websocket_command({
|
||||
vol.Required("type"): WS_CONNECT,
|
||||
vol.Required("deviceID"): str,
|
||||
})
|
||||
def handle_connect(hass, connection, msg):
|
||||
_LOGGER.error("--------------------")
|
||||
_LOGGER.error("CONNECTING BM")
|
||||
deviceID = msg["deviceID"]
|
||||
|
||||
device = get_devices(hass).get(deviceID, BrowserModConnection(hass, deviceID))
|
||||
device.connect(connection, msg["id"])
|
||||
get_devices(hass)[deviceID] = device
|
||||
|
||||
_LOGGER.error("DONE")
|
||||
connection.send_message(result_message(msg["id"]))
|
||||
|
||||
@websocket_command({
|
||||
@ -35,9 +30,6 @@ async def setup_connection(hass, config):
|
||||
vol.Optional("data"): dict,
|
||||
})
|
||||
def handle_update( hass, connection, msg):
|
||||
_LOGGER.error("--------------------")
|
||||
_LOGGER.error("UPDATING BM")
|
||||
_LOGGER.error(msg)
|
||||
devices = get_devices(hass)
|
||||
deviceID = msg["deviceID"]
|
||||
if deviceID in devices:
|
||||
@ -56,11 +48,10 @@ class BrowserModConnection:
|
||||
self.media_player = None
|
||||
self.screen = None
|
||||
self.sensor = None
|
||||
self.fully = None
|
||||
|
||||
def connect(self, connection, cid):
|
||||
self.connection.append((connection, cid))
|
||||
_LOGGER.error("********************")
|
||||
_LOGGER.error("Connected %s", self.deviceID)
|
||||
self.send("update")
|
||||
|
||||
def disconnect():
|
||||
@ -77,15 +68,6 @@ class BrowserModConnection:
|
||||
}))
|
||||
|
||||
def update(self, data):
|
||||
_LOGGER.error("********************")
|
||||
_LOGGER.error("Got update %s for %s", data, self.deviceID)
|
||||
if data.get('player'):
|
||||
self.media_player = self.media_player or create_entity(
|
||||
self.hass,
|
||||
'media_player',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.media_player.data = data.get('player')
|
||||
if data.get('browser'):
|
||||
self.sensor = self.sensor or create_entity(
|
||||
self.hass,
|
||||
@ -93,6 +75,15 @@ class BrowserModConnection:
|
||||
self.deviceID,
|
||||
self)
|
||||
self.sensor.data = data.get('browser')
|
||||
|
||||
if data.get('player'):
|
||||
self.media_player = self.media_player or create_entity(
|
||||
self.hass,
|
||||
'media_player',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.media_player.data = data.get('player')
|
||||
|
||||
if data.get('screen'):
|
||||
self.screen = self.screen or create_entity(
|
||||
self.hass,
|
||||
@ -101,3 +92,11 @@ class BrowserModConnection:
|
||||
self)
|
||||
self.screen.data = data.get('screen')
|
||||
|
||||
if data.get('fully'):
|
||||
self.fully = self.fully or create_entity(
|
||||
self.hass,
|
||||
'binary_sensor',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.fully.data = data.get('fully')
|
||||
|
||||
|
@ -16,8 +16,6 @@ def get_alias(hass, deviceID):
|
||||
return None
|
||||
|
||||
def create_entity(hass, platform, deviceID, connection):
|
||||
_LOGGER.error("********************")
|
||||
_LOGGER.error("Creating %s for %s", platform, deviceID)
|
||||
adder = hass.data[DOMAIN][DATA_ADDERS][platform]
|
||||
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
|
||||
return entity
|
||||
|
@ -36,6 +36,7 @@ class BrowserModPlayer(MediaPlayerDevice, BrowserModEntity):
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
}
|
||||
|
||||
@property
|
||||
|
@ -32,5 +32,6 @@ class BrowserModSensor(BrowserModEntity):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"last_seen": self.last_seen,
|
||||
"deviceID": self.deviceID,
|
||||
**self.data
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ def setup_service(hass):
|
||||
|
||||
for t in targets:
|
||||
if t in devices:
|
||||
devices[t].ws_send(command, **data)
|
||||
devices[t].send(command, **data)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'command', handle_command)
|
||||
|
4
info.md
4
info.md
@ -5,11 +5,11 @@ A Home Assistant integration to turn your browser into a controllable entity - a
|
||||
|
||||
## Example uses
|
||||
|
||||
- Make the camera feed from your front door pop up on the tablett in your kitchen when someone rings the doorbell.
|
||||
- Make the camera feed from your front door pop up on the tablet in your kitchen when someone rings the doorbell.
|
||||
- Have a message pop up on every screen in the house when it's bedtime.
|
||||
- Make the browser on your workstation switch to a specific tab when the kitchen light is on after midnight
|
||||
- Play a TTS message on your work computer when the traffic sensor tells you it's time to go home.
|
||||
- Make the screen on your tablett go black during the night, but wake up when you touch it.
|
||||
- Make the screen on your tablet go black during the night, but wake up when you touch it.
|
||||
|
||||
### See [README](https://github.com/thomasloven/hass-browser_mod/blob/master/README.md) for usage instructions
|
||||
|
||||
|
76
js/main.js
76
js/main.js
@ -13,12 +13,10 @@ class BrowserMod {
|
||||
if(this.hassPatched) return;
|
||||
const callService = hass.callService;
|
||||
const newCallService = (domain, service, serviceData) => {
|
||||
if(domain === "browser_mod" && service === "command") {
|
||||
if(serviceData.deviceID) {
|
||||
const index = serviceData.deviceID.indexOf('this');
|
||||
if(index !== -1)
|
||||
serviceData.deviceID[index] = deviceID;
|
||||
}
|
||||
if(serviceData && serviceData.deviceID) {
|
||||
const index = serviceData.deviceID.indexOf('this');
|
||||
if(index !== -1)
|
||||
serviceData.deviceID[index] = deviceID;
|
||||
}
|
||||
return callService(domain, service, serviceData);
|
||||
};
|
||||
@ -61,9 +59,18 @@ class BrowserMod {
|
||||
this._motionTimeout = undefined;
|
||||
fully.bind('screenOn', 'browser_mod.update();');
|
||||
fully.bind('screenOff', 'browser_mod.update();');
|
||||
fully.bind('pluggedAC', 'browser_mod.update();');
|
||||
fully.bind('pluggedUSB', 'browser_mod.update();');
|
||||
fully.bind('onBatteryLevelChanged', 'browser_mod.update();');
|
||||
fully.bind('unplugged', 'browser_mod.update();');
|
||||
fully.bind('networkReconnect', 'browser_mod.update();');
|
||||
|
||||
fully.bind('onMotion', 'browser_mod.fullyMotion();');
|
||||
}
|
||||
|
||||
this._screenSaver = undefined;
|
||||
this._screenSaverTimer = undefined;
|
||||
this._screenSaverTime = 0;
|
||||
this._blackout = document.createElement("div");
|
||||
this._blackout.style.cssText = `
|
||||
position: fixed;
|
||||
@ -84,7 +91,6 @@ class BrowserMod {
|
||||
conn.subscribeMessage((msg) => this.callback(msg), {
|
||||
type: 'browser_mod/connect',
|
||||
deviceID: deviceID,
|
||||
fully: window.fully ? true : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@ -181,13 +187,31 @@ class BrowserMod {
|
||||
popup(msg){
|
||||
if(!msg.title && !msg.auto_close) return;
|
||||
if(!msg.card) return;
|
||||
popUp(msg.title, msg.card, msg.large, msg.style, msg.auto_close);
|
||||
if(msg.auto_close)
|
||||
this.autoclose_popup_active = true;
|
||||
const fn = () => {
|
||||
popUp(msg.title, msg.card, msg.large, msg.style, msg.auto_close);
|
||||
if(auto_close)
|
||||
this.autoclose_popup_active = true;
|
||||
};
|
||||
if(msg.auto_close && msg.time) {
|
||||
msg.time = parseInt(msg.time)
|
||||
if(msg.time == -1) {
|
||||
clearTimeout(this._screenSaverTimer);
|
||||
this._screenSaverTime = 0;
|
||||
return;
|
||||
}
|
||||
this._screenSaverTime = msg.time * 1000;
|
||||
this._screenSaver = fn;
|
||||
this._screenSaverTimer = setTimeout(this._screenSaver, this._screenSaverTime)
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
close_popup(msg){
|
||||
this.autoclose_popup_active = false;
|
||||
closePopUp();
|
||||
if(this._screenSaverTime) {
|
||||
this._screenSaverTimer = setTimeout(this._screenSaver, this._screenSaverTime)
|
||||
}
|
||||
}
|
||||
navigate(msg){
|
||||
if(!msg.navigation_path) return;
|
||||
@ -210,15 +234,32 @@ class BrowserMod {
|
||||
}
|
||||
|
||||
blackout(msg){
|
||||
if (window.fully)
|
||||
{
|
||||
fully.turnScreenOff();
|
||||
const fn = () => {
|
||||
if (window.fully)
|
||||
{
|
||||
fully.turnScreenOff();
|
||||
} else {
|
||||
this._blackout.style.visibility = "visible";
|
||||
}
|
||||
this.update();
|
||||
};
|
||||
if(msg.time) {
|
||||
msg.time = parseInt(msg.time)
|
||||
if(msg.time == -1) {
|
||||
clearTimeout(this._screenSaverTimer);
|
||||
this._screenSaverTime = 0;
|
||||
return;
|
||||
}
|
||||
this._screenSaverTime = msg.time * 1000;
|
||||
this._screenSaver = fn;
|
||||
this._screenSaverTimer = setTimeout(this._screenSaver, this._screenSaverTime)
|
||||
} else {
|
||||
this._blackout.style.visibility = "visible";
|
||||
fn();
|
||||
}
|
||||
this.update();
|
||||
}
|
||||
no_blackout(msg){
|
||||
|
||||
clearTimeout(this._screenSaverTimer);
|
||||
if(this.autoclose_popup_active)
|
||||
return this.close_popup();
|
||||
if (window.fully)
|
||||
@ -234,6 +275,9 @@ class BrowserMod {
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
if(this._screenSaverTime) {
|
||||
this._screenSaverTimer = setTimeout(this._screenSaver, this._screenSaverTime)
|
||||
}
|
||||
}
|
||||
is_blackout(){
|
||||
if (window.fully)
|
||||
@ -269,6 +313,8 @@ class BrowserMod {
|
||||
userAgent: navigator.userAgent,
|
||||
currentUser: this._hass && this._hass.user && this._hass.user.name,
|
||||
fullyKiosk: window.fully ? true : undefined,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
},
|
||||
player: {
|
||||
volume: this.player.volume,
|
||||
|
Loading…
x
Reference in New Issue
Block a user