Add experimental camera support
This commit is contained in:
@@ -3,7 +3,7 @@ import logging
|
||||
from .mod_view import setup_view
|
||||
from .connection import setup_connection
|
||||
from .service import setup_service
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES, DATA_CONFIG
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -22,12 +22,14 @@ async def async_setup(hass, config):
|
||||
DATA_DEVICES: {},
|
||||
DATA_ALIASES: aliases,
|
||||
DATA_ADDERS: {},
|
||||
DATA_CONFIG: config[DOMAIN].get(CONFIG_DEVICES, {}),
|
||||
}
|
||||
|
||||
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 hass.helpers.discovery.async_load_platform("camera", DOMAIN, {}, config)
|
||||
|
||||
await setup_connection(hass, config)
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
36
custom_components/browser_mod/camera.py
Normal file
36
custom_components/browser_mod/camera.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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'
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModCamera)
|
||||
|
||||
class BrowserModCamera(Camera, BrowserModEntity):
|
||||
domain = PLATFORM
|
||||
|
||||
def __init__(self, hass, connection, deviceID, alias=None):
|
||||
Camera.__init__(self)
|
||||
BrowserModEntity.__init__(self, hass, connection, deviceID, alias)
|
||||
self.last_seen = None
|
||||
|
||||
def updated(self):
|
||||
self.last_seen = datetime.now()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def camera_image(self):
|
||||
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,
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import voluptuous as vol
|
||||
from homeassistant.components.websocket_api import websocket_command, result_message, event_message, async_register_command
|
||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||
|
||||
from .const import DOMAIN, WS_CONNECT, WS_UPDATE
|
||||
from .helpers import get_devices, create_entity
|
||||
from .const import DOMAIN, WS_CONNECT, WS_UPDATE, WS_CAMERA
|
||||
from .helpers import get_devices, create_entity, get_config
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -38,7 +38,6 @@ async def setup_connection(hass, config):
|
||||
async_register_command(hass, handle_connect)
|
||||
async_register_command(hass, handle_update)
|
||||
|
||||
|
||||
class BrowserModConnection:
|
||||
def __init__(self, hass, deviceID):
|
||||
self.hass = hass
|
||||
@@ -49,10 +48,11 @@ class BrowserModConnection:
|
||||
self.screen = None
|
||||
self.sensor = None
|
||||
self.fully = None
|
||||
self.camera = None
|
||||
|
||||
def connect(self, connection, cid):
|
||||
self.connection.append((connection, cid))
|
||||
self.send("update")
|
||||
self.send("update", **get_config(self.hass, self.deviceID))
|
||||
|
||||
def disconnect():
|
||||
self.connection.remove((connection, cid))
|
||||
@@ -100,3 +100,11 @@ class BrowserModConnection:
|
||||
self)
|
||||
self.fully.data = data.get('fully')
|
||||
|
||||
if data.get('camera'):
|
||||
self.camera = self.camera or create_entity(
|
||||
self.hass,
|
||||
'camera',
|
||||
self.deviceID,
|
||||
self)
|
||||
self.camera.data = data.get('camera')
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@ DATA_EXTRA_MODULE_URL = 'frontend_extra_module_url'
|
||||
DATA_DEVICES = "devices"
|
||||
DATA_ALIASES = "aliases"
|
||||
DATA_ADDERS = "adders"
|
||||
DATA_CONFIG = "config"
|
||||
|
||||
CONFIG_DEVICES = "devices"
|
||||
|
||||
WS_ROOT = DOMAIN
|
||||
WS_CONNECT = "{}/connect".format(WS_ROOT)
|
||||
WS_UPDATE = "{}/update".format(WS_ROOT)
|
||||
WS_CAMERA = "{}/camera".format(WS_ROOT)
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
|
||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES, DATA_CONFIG
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -15,6 +15,10 @@ def get_alias(hass, deviceID):
|
||||
return k
|
||||
return None
|
||||
|
||||
def get_config(hass, deviceID):
|
||||
config = hass.data[DOMAIN][DATA_CONFIG]
|
||||
return config.get(deviceID, config.get(deviceID.replace('-','_'), {}))
|
||||
|
||||
def create_entity(hass, platform, deviceID, connection):
|
||||
adder = hass.data[DOMAIN][DATA_ADDERS][platform]
|
||||
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
|
||||
|
||||
@@ -37,6 +37,8 @@ class BrowserModLight(Light, BrowserModEntity):
|
||||
def device_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user