Restructuring complete. Timeouts on popups. Fully Kiosk compatibility.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user