Code linting
This commit is contained in:
@@ -31,11 +31,7 @@ async def async_setup(hass, config):
|
||||
if not hass.config_entries.async_entries(DOMAIN):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": config_entries.SOURCE_IMPORT
|
||||
},
|
||||
data={}
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -43,7 +39,7 @@ async def async_setup(hass, config):
|
||||
for d in config[DOMAIN].get(CONFIG_DEVICES, {}):
|
||||
name = config[DOMAIN][CONFIG_DEVICES][d].get("name", None)
|
||||
if name:
|
||||
aliases[name] = d.replace('_', '-')
|
||||
aliases[name] = d.replace("_", "-")
|
||||
|
||||
hass.data[DOMAIN] = {
|
||||
DATA_DEVICES: {},
|
||||
@@ -51,19 +47,14 @@ async def async_setup(hass, config):
|
||||
DATA_ADDERS: {},
|
||||
DATA_CONFIG: config[DOMAIN],
|
||||
DATA_SETUP_COMPLETE: False,
|
||||
}
|
||||
}
|
||||
|
||||
await setup_connection(hass, config)
|
||||
setup_view(hass)
|
||||
|
||||
for component in COMPONENTS:
|
||||
hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform(
|
||||
component,
|
||||
DOMAIN,
|
||||
{},
|
||||
config
|
||||
)
|
||||
hass.helpers.discovery.async_load_platform(component, DOMAIN, {}, config)
|
||||
)
|
||||
|
||||
await setup_service(hass)
|
||||
@@ -79,9 +70,6 @@ async def async_setup(hass, config):
|
||||
async def async_setup_entry(hass, config_entry):
|
||||
for component in COMPONENTS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(
|
||||
config_entry,
|
||||
component
|
||||
)
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, component)
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF
|
||||
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'
|
||||
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)
|
||||
@@ -31,14 +37,13 @@ class BrowserModSensor(BrowserModEntity):
|
||||
def state(self):
|
||||
if not self.connection.connection:
|
||||
return STATE_UNAVAILABLE
|
||||
if self.data.get('motion', False):
|
||||
if self.data.get("motion", False):
|
||||
return STATE_ON
|
||||
return STATE_OFF
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return not self.data.get('motion', False)
|
||||
|
||||
return not self.data.get("motion", False)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
@@ -47,9 +52,9 @@ class BrowserModSensor(BrowserModEntity):
|
||||
@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
|
||||
}
|
||||
"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,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import base64
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_ON, STATE_OFF, STATE_IDLE
|
||||
from homeassistant.components.camera import Camera
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
PLATFORM = 'camera'
|
||||
PLATFORM = "camera"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModCamera)
|
||||
@@ -31,12 +30,12 @@ class BrowserModCamera(Camera, BrowserModEntity):
|
||||
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):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ from homeassistant import config_entries
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class BrowserModConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
@@ -5,7 +5,7 @@ from homeassistant.components.websocket_api import (
|
||||
websocket_command,
|
||||
result_message,
|
||||
event_message,
|
||||
async_register_command
|
||||
async_register_command,
|
||||
)
|
||||
|
||||
from .const import WS_CONNECT, WS_UPDATE
|
||||
@@ -15,26 +15,28 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def setup_connection(hass, config):
|
||||
|
||||
@websocket_command({
|
||||
vol.Required("type"): WS_CONNECT,
|
||||
vol.Required("deviceID"): str,
|
||||
})
|
||||
@websocket_command(
|
||||
{
|
||||
vol.Required("type"): WS_CONNECT,
|
||||
vol.Required("deviceID"): str,
|
||||
}
|
||||
)
|
||||
def handle_connect(hass, connection, msg):
|
||||
deviceID = msg["deviceID"]
|
||||
|
||||
device = get_devices(hass).get(deviceID,
|
||||
BrowserModConnection(hass, deviceID))
|
||||
device = get_devices(hass).get(deviceID, BrowserModConnection(hass, deviceID))
|
||||
device.connect(connection, msg["id"])
|
||||
get_devices(hass)[deviceID] = device
|
||||
|
||||
connection.send_message(result_message(msg["id"]))
|
||||
|
||||
@websocket_command({
|
||||
vol.Required("type"): WS_UPDATE,
|
||||
vol.Required("deviceID"): str,
|
||||
vol.Optional("data"): dict,
|
||||
})
|
||||
@websocket_command(
|
||||
{
|
||||
vol.Required("type"): WS_UPDATE,
|
||||
vol.Required("deviceID"): str,
|
||||
vol.Optional("data"): dict,
|
||||
}
|
||||
)
|
||||
def handle_update(hass, connection, msg):
|
||||
devices = get_devices(hass)
|
||||
deviceID = msg["deviceID"]
|
||||
@@ -69,57 +71,52 @@ class BrowserModConnection:
|
||||
def send(self, command, **kwargs):
|
||||
if self.connection:
|
||||
connection, cid = self.connection[-1]
|
||||
connection.send_message(event_message(cid, {
|
||||
"command": command,
|
||||
**kwargs,
|
||||
}))
|
||||
connection.send_message(
|
||||
event_message(
|
||||
cid,
|
||||
{
|
||||
"command": command,
|
||||
**kwargs,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
def trigger_update(self):
|
||||
if is_setup_complete(self.hass):
|
||||
self.send("update", **get_config(self.hass, self.deviceID))
|
||||
|
||||
def update(self, data):
|
||||
if data.get('browser'):
|
||||
if data.get("browser"):
|
||||
self.sensor = self.sensor or create_entity(
|
||||
self.hass,
|
||||
'sensor',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.hass, "sensor", self.deviceID, self
|
||||
)
|
||||
if self.sensor:
|
||||
self.sensor.data = data.get('browser')
|
||||
self.sensor.data = data.get("browser")
|
||||
|
||||
if data.get('player'):
|
||||
if data.get("player"):
|
||||
self.media_player = self.media_player or create_entity(
|
||||
self.hass,
|
||||
'media_player',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.hass, "media_player", self.deviceID, self
|
||||
)
|
||||
if self.media_player:
|
||||
self.media_player.data = data.get('player')
|
||||
self.media_player.data = data.get("player")
|
||||
|
||||
if data.get('screen'):
|
||||
if data.get("screen"):
|
||||
self.screen = self.screen or create_entity(
|
||||
self.hass,
|
||||
'light',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.hass, "light", self.deviceID, self
|
||||
)
|
||||
if self.screen:
|
||||
self.screen.data = data.get('screen')
|
||||
self.screen.data = data.get("screen")
|
||||
|
||||
if data.get('fully'):
|
||||
if data.get("fully"):
|
||||
self.fully = self.fully or create_entity(
|
||||
self.hass,
|
||||
'binary_sensor',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.hass, "binary_sensor", self.deviceID, self
|
||||
)
|
||||
if self.fully:
|
||||
self.fully.data = data.get('fully')
|
||||
self.fully.data = data.get("fully")
|
||||
|
||||
if data.get('camera'):
|
||||
if data.get("camera"):
|
||||
self.camera = self.camera or create_entity(
|
||||
self.hass,
|
||||
'camera',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.hass, "camera", self.deviceID, self
|
||||
)
|
||||
if self.camera:
|
||||
self.camera.data = data.get('camera')
|
||||
self.camera.data = data.get("camera")
|
||||
|
||||
@@ -2,7 +2,7 @@ DOMAIN = "browser_mod"
|
||||
|
||||
FRONTEND_SCRIPT_URL = "/browser_mod.js"
|
||||
|
||||
DATA_EXTRA_MODULE_URL = 'frontend_extra_module_url'
|
||||
DATA_EXTRA_MODULE_URL = "frontend_extra_module_url"
|
||||
|
||||
DATA_DEVICES = "devices"
|
||||
DATA_ALIASES = "aliases"
|
||||
@@ -21,18 +21,18 @@ WS_UPDATE = "{}/update".format(WS_ROOT)
|
||||
WS_CAMERA = "{}/camera".format(WS_ROOT)
|
||||
|
||||
USER_COMMANDS = [
|
||||
"debug",
|
||||
"popup",
|
||||
"close-popup",
|
||||
"navigate",
|
||||
"more-info",
|
||||
"set-theme",
|
||||
"lovelace-reload",
|
||||
"window-reload",
|
||||
"blackout",
|
||||
"no-blackout",
|
||||
"toast",
|
||||
"commands",
|
||||
"call_service",
|
||||
"delay",
|
||||
]
|
||||
"debug",
|
||||
"popup",
|
||||
"close-popup",
|
||||
"navigate",
|
||||
"more-info",
|
||||
"set-theme",
|
||||
"lovelace-reload",
|
||||
"window-reload",
|
||||
"blackout",
|
||||
"no-blackout",
|
||||
"toast",
|
||||
"commands",
|
||||
"call_service",
|
||||
"delay",
|
||||
]
|
||||
|
||||
@@ -31,18 +31,20 @@ def get_alias(hass, deviceID):
|
||||
|
||||
def get_config(hass, deviceID):
|
||||
config = hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DEVICES, {})
|
||||
return config.get(deviceID, config.get(deviceID.replace('-', '_'), {}))
|
||||
return config.get(deviceID, config.get(deviceID.replace("-", "_"), {}))
|
||||
|
||||
|
||||
def create_entity(hass, platform, deviceID, connection):
|
||||
conf = get_config(hass, deviceID)
|
||||
if conf and (platform in conf.get(CONFIG_DISABLE, [])
|
||||
or CONFIG_DISABLE_ALL in conf.get(CONFIG_DISABLE, [])):
|
||||
if conf and (
|
||||
platform in conf.get(CONFIG_DISABLE, [])
|
||||
or CONFIG_DISABLE_ALL in conf.get(CONFIG_DISABLE, [])
|
||||
):
|
||||
return None
|
||||
if not conf and \
|
||||
(platform in hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])
|
||||
or CONFIG_DISABLE_ALL in
|
||||
hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])):
|
||||
if not conf and (
|
||||
platform in hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])
|
||||
or CONFIG_DISABLE_ALL in hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])
|
||||
):
|
||||
return None
|
||||
adder = hass.data[DOMAIN][DATA_ADDERS][platform]
|
||||
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
|
||||
@@ -57,6 +59,7 @@ def setup_platform(hass, config, async_add_devices, platform, cls):
|
||||
entity = cls(hass, connection, deviceID, alias)
|
||||
async_add_devices([entity])
|
||||
return entity
|
||||
|
||||
hass.data[DOMAIN][DATA_ADDERS][platform] = adder
|
||||
return True
|
||||
|
||||
@@ -66,19 +69,16 @@ def is_setup_complete(hass):
|
||||
|
||||
|
||||
class BrowserModEntity(Entity):
|
||||
|
||||
def __init__(self, hass, connection, deviceID, alias=None):
|
||||
self.hass = hass
|
||||
self.connection = connection
|
||||
self.deviceID = deviceID
|
||||
self._data = {}
|
||||
self._alias = alias
|
||||
prefix = hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_PREFIX, '')
|
||||
prefix = hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_PREFIX, "")
|
||||
self.entity_id = async_generate_entity_id(
|
||||
self.domain+".{}",
|
||||
alias or f"{prefix}{deviceID}",
|
||||
hass=hass
|
||||
)
|
||||
self.domain + ".{}", alias or f"{prefix}{deviceID}", hass=hass
|
||||
)
|
||||
|
||||
def updated(self):
|
||||
pass
|
||||
@@ -86,10 +86,8 @@ class BrowserModEntity(Entity):
|
||||
@property
|
||||
def device_info(self):
|
||||
return {
|
||||
"identifiers": {
|
||||
(DOMAIN, self.deviceID)
|
||||
},
|
||||
"name": self._alias or self.deviceID
|
||||
"identifiers": {(DOMAIN, self.deviceID)},
|
||||
"name": self._alias or self.deviceID,
|
||||
}
|
||||
|
||||
@property
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_ON, STATE_OFF
|
||||
@@ -6,7 +5,8 @@ from homeassistant.components.light import LightEntity, SUPPORT_BRIGHTNESS
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
PLATFORM = 'light'
|
||||
PLATFORM = "light"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModLight)
|
||||
@@ -31,31 +31,31 @@ class BrowserModLight(LightEntity, BrowserModEntity):
|
||||
def state(self):
|
||||
if not self.connection.connection:
|
||||
return STATE_UNAVAILABLE
|
||||
if self.data.get('blackout', False):
|
||||
if self.data.get("blackout", False):
|
||||
return STATE_OFF
|
||||
return STATE_ON
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return not self.data.get('blackout', False)
|
||||
return not self.data.get("blackout", False)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
if self.data.get('brightness', False):
|
||||
if self.data.get("brightness", False):
|
||||
return SUPPORT_BRIGHTNESS
|
||||
return 0
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
return self.data.get('brightness', None)
|
||||
return self.data.get("brightness", None)
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
self.connection.send("no-blackout", **kwargs)
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
import logging
|
||||
from homeassistant.components.media_player import (
|
||||
SUPPORT_PLAY, SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_PAUSE, SUPPORT_STOP,
|
||||
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_MUTE,
|
||||
MediaPlayerEntity,
|
||||
)
|
||||
SUPPORT_PLAY,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_MUTE,
|
||||
MediaPlayerEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
STATE_IDLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
STATE_IDLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM = 'media_player'
|
||||
PLATFORM = "media_player"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModPlayer)
|
||||
@@ -40,9 +44,9 @@ class BrowserModPlayer(MediaPlayerEntity, BrowserModEntity):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
}
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
}
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@@ -50,37 +54,48 @@ class BrowserModPlayer(MediaPlayerEntity, BrowserModEntity):
|
||||
return STATE_UNAVAILABLE
|
||||
state = self.data.get("state", "unknown")
|
||||
return {
|
||||
"playing": STATE_PLAYING,
|
||||
"paused": STATE_PAUSED,
|
||||
"stopped": STATE_IDLE,
|
||||
}.get(state, STATE_UNKNOWN)
|
||||
"playing": STATE_PLAYING,
|
||||
"paused": STATE_PAUSED,
|
||||
"stopped": STATE_IDLE,
|
||||
}.get(state, STATE_UNKNOWN)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
return (
|
||||
SUPPORT_PLAY | SUPPORT_PLAY_MEDIA |
|
||||
SUPPORT_PAUSE | SUPPORT_STOP |
|
||||
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE
|
||||
)
|
||||
SUPPORT_PLAY
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_PAUSE
|
||||
| SUPPORT_STOP
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
)
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
return self.data.get("volume", 0)
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
return self.data.get("muted", False)
|
||||
|
||||
@property
|
||||
def media_content_id(self):
|
||||
return self.data.get("src", "")
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
self.connection.send("set_volume", volume_level=volume)
|
||||
|
||||
def mute_volume(self, mute):
|
||||
self.connection.send("mute", mute=mute)
|
||||
|
||||
def play_media(self, media_type, media_id, **kwargs):
|
||||
self.connection.send("play", media_content_id=media_id)
|
||||
|
||||
def media_play(self):
|
||||
self.connection.send("play")
|
||||
|
||||
def media_pause(self):
|
||||
self.connection.send("pause")
|
||||
|
||||
def media_stop(self):
|
||||
self.connection.send("stop")
|
||||
|
||||
@@ -12,6 +12,7 @@ def setup_view(hass):
|
||||
|
||||
hass.http.register_view(ModView(hass, FRONTEND_SCRIPT_URL))
|
||||
|
||||
|
||||
class ModView(HomeAssistantView):
|
||||
|
||||
name = "browser_mod_script"
|
||||
@@ -33,4 +34,6 @@ class ModView(HomeAssistantView):
|
||||
except Exception as exception:
|
||||
pass
|
||||
|
||||
return web.Response(body=filecontent, content_type="text/javascript", charset="utf-8")
|
||||
return web.Response(
|
||||
body=filecontent, content_type="text/javascript", charset="utf-8"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,8 @@ from homeassistant.const import STATE_UNAVAILABLE
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
PLATFORM = 'sensor'
|
||||
PLATFORM = "sensor"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModSensor)
|
||||
@@ -35,8 +36,8 @@ class BrowserModSensor(BrowserModEntity):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"last_seen": self.last_seen,
|
||||
"deviceID": self.deviceID,
|
||||
**self.data
|
||||
}
|
||||
"type": "browser_mod",
|
||||
"last_seen": self.last_seen,
|
||||
"deviceID": self.deviceID,
|
||||
**self.data,
|
||||
}
|
||||
|
||||
@@ -2,20 +2,23 @@ import logging
|
||||
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
async_entries_for_config_entry,
|
||||
async_entries_for_device
|
||||
async_entries_for_device,
|
||||
)
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
|
||||
from .const import (
|
||||
DOMAIN, DATA_DEVICES, DATA_ALIASES,
|
||||
USER_COMMANDS, DATA_CONFIG, CONFIG_DEVICES
|
||||
DOMAIN,
|
||||
DATA_DEVICES,
|
||||
DATA_ALIASES,
|
||||
USER_COMMANDS,
|
||||
DATA_CONFIG,
|
||||
CONFIG_DEVICES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def setup_service(hass):
|
||||
|
||||
def handle_command(call):
|
||||
command = call.data.get("command", None)
|
||||
if not command:
|
||||
@@ -38,23 +41,19 @@ async def setup_service(hass):
|
||||
devices[t].send(command, **data)
|
||||
|
||||
def command_wrapper(call):
|
||||
command = call.service.replace('_', '-')
|
||||
command = call.service.replace("_", "-")
|
||||
call.data = dict(call.data)
|
||||
call.data['command'] = command
|
||||
call.data["command"] = command
|
||||
handle_command(call)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'command', handle_command)
|
||||
hass.services.async_register(DOMAIN, "command", handle_command)
|
||||
for cmd in USER_COMMANDS:
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
cmd.replace('-', '_'),
|
||||
command_wrapper
|
||||
)
|
||||
hass.services.async_register(DOMAIN, cmd.replace("-", "_"), command_wrapper)
|
||||
|
||||
async def call_service(service_call):
|
||||
await async_clean_devices(hass, service_call.data)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'clean_devices', call_service)
|
||||
hass.services.async_register(DOMAIN, "clean_devices", call_service)
|
||||
|
||||
|
||||
async def async_clean_devices(hass, data):
|
||||
@@ -63,14 +62,12 @@ async def async_clean_devices(hass, data):
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
entity_entries = async_entries_for_config_entry(
|
||||
entity_registry,
|
||||
config_entry.entry_id
|
||||
entity_registry, config_entry.entry_id
|
||||
)
|
||||
|
||||
device_entries = [
|
||||
entry
|
||||
for entry
|
||||
in device_registry.devices.values()
|
||||
for entry in device_registry.devices.values()
|
||||
if config_entry.entry_id in entry.config_entries
|
||||
]
|
||||
|
||||
@@ -103,7 +100,4 @@ async def async_clean_devices(hass, data):
|
||||
|
||||
devices = hass.data[DOMAIN][DATA_DEVICES]
|
||||
for rec in devices:
|
||||
devices[rec].send(
|
||||
'toast',
|
||||
message=f"Removed devices: {removed}"
|
||||
)
|
||||
devices[rec].send("toast", message=f"Removed devices: {removed}")
|
||||
|
||||
@@ -1,128 +1,128 @@
|
||||
command:
|
||||
description: 'Send a command to a browser.'
|
||||
description: "Send a command to a browser."
|
||||
fields:
|
||||
command:
|
||||
description: 'Command to send'
|
||||
example: 'navigate'
|
||||
description: "Command to send"
|
||||
example: "navigate"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
commands:
|
||||
description: 'Send several commands to a browser'
|
||||
description: "Send several commands to a browser"
|
||||
fields:
|
||||
commands:
|
||||
description: "List of commands to send"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
debug:
|
||||
description: 'On all browsers, show a popup, and a javascript alert with the current device ID.'
|
||||
description: "On all browsers, show a popup, and a javascript alert with the current device ID."
|
||||
fields:
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
set_theme:
|
||||
description: 'On all browsers, change the theme.'
|
||||
description: "On all browsers, change the theme."
|
||||
fields:
|
||||
theme:
|
||||
description: 'Theme to change to'
|
||||
description: "Theme to change to"
|
||||
example: '{theme: "clear_light"}'
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
navigate:
|
||||
description: 'Navigate to a path on a browser.'
|
||||
description: "Navigate to a path on a browser."
|
||||
fields:
|
||||
navigation_path:
|
||||
description: 'Path to navigate to'
|
||||
example: '/lovelace/1'
|
||||
description: "Path to navigate to"
|
||||
example: "/lovelace/1"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
more_info:
|
||||
description: 'Open the more info dialog of an entity on a browser.'
|
||||
description: "Open the more info dialog of an entity on a browser."
|
||||
fields:
|
||||
entity_id:
|
||||
description: 'Entity to show more info for'
|
||||
example: 'camera.front_door'
|
||||
description: "Entity to show more info for"
|
||||
example: "camera.front_door"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
large:
|
||||
description: '(optional) Set to true to make wider'
|
||||
example: 'true'
|
||||
description: "(optional) Set to true to make wider"
|
||||
example: "true"
|
||||
toast:
|
||||
description: 'Show a toast message in the bottom left on all browsers.'
|
||||
description: "Show a toast message in the bottom left on all browsers."
|
||||
fields:
|
||||
message:
|
||||
description: 'Message to show'
|
||||
example: 'Short message'
|
||||
description: "Message to show"
|
||||
example: "Short message"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
duration:
|
||||
description: '(optional) Time in milliseconds to show message for. Set to 0 for persistent display.'
|
||||
example: '10000'
|
||||
description: "(optional) Time in milliseconds to show message for. Set to 0 for persistent display."
|
||||
example: "10000"
|
||||
popup:
|
||||
description: 'Pop up a card on a browser.'
|
||||
description: "Pop up a card on a browser."
|
||||
fields:
|
||||
title:
|
||||
description: 'Name to show in popup bar'
|
||||
example: 'Popup example'
|
||||
description: "Name to show in popup bar"
|
||||
example: "Popup example"
|
||||
card:
|
||||
description: 'YAML config for card to show'
|
||||
description: "YAML config for card to show"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
large:
|
||||
description: '(optional) Set to true to make wider'
|
||||
example: 'true'
|
||||
description: "(optional) Set to true to make wider"
|
||||
example: "true"
|
||||
hide_header:
|
||||
description: '(optional) Hide header title and close button'
|
||||
example: 'true'
|
||||
description: "(optional) Hide header title and close button"
|
||||
example: "true"
|
||||
auto_close:
|
||||
description: '(optional) Close popup when mouse is moved or key is pressed. Also hides header'
|
||||
example: 'true'
|
||||
description: "(optional) Close popup when mouse is moved or key is pressed. Also hides header"
|
||||
example: "true"
|
||||
time:
|
||||
description: "(optional) When mouse isn't moved or keys aren't pressed for this amount of seconds, reopen. Only usable with auto_close. See blackout"
|
||||
example: '20'
|
||||
example: "20"
|
||||
close_popup:
|
||||
description: 'Close all popups on all browsers.'
|
||||
description: "Close all popups on all browsers."
|
||||
fields:
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
blackout:
|
||||
description: 'Cover screen in black until the mouse is moved or a key is pressed.'
|
||||
description: "Cover screen in black until the mouse is moved or a key is pressed."
|
||||
fields:
|
||||
time:
|
||||
description: '(optional) The blackout will 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.'
|
||||
example: '20'
|
||||
description: "(optional) The blackout will 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."
|
||||
example: "20"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
no_blackout:
|
||||
description: 'Remove a blackout from a browser.'
|
||||
description: "Remove a blackout from a browser."
|
||||
fields:
|
||||
brightness:
|
||||
description: '(optional) On a Fully Kiosk Browser Plus set the screen brightness from 0 - 255.'
|
||||
description: "(optional) On a Fully Kiosk Browser Plus set the screen brightness from 0 - 255."
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
lovelace_reload:
|
||||
description: 'Refresh the lovelace configuration.'
|
||||
description: "Refresh the lovelace configuration."
|
||||
fields:
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
delay:
|
||||
description: 'Do nothing for a while'
|
||||
description: "Do nothing for a while"
|
||||
fields:
|
||||
seconds:
|
||||
description: 'Number of seconds to delay'
|
||||
example: '5'
|
||||
description: "Number of seconds to delay"
|
||||
example: "5"
|
||||
deviceID:
|
||||
description: '(optional) List of receiving browsers'
|
||||
description: "(optional) List of receiving browsers"
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
||||
call_service:
|
||||
description: ""
|
||||
|
||||
Reference in New Issue
Block a user