Added camera functionality
This commit is contained in:
@@ -1,45 +1,40 @@
|
||||
from datetime import datetime
|
||||
import base64
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
from .helpers import BrowserModEntity
|
||||
from .const import DOMAIN, DATA_ADDERS
|
||||
|
||||
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)
|
||||
async def async_setup_platform(
|
||||
hass, config_entry, async_add_entities, discoveryInfo=None
|
||||
):
|
||||
hass.data[DOMAIN][DATA_ADDERS]["camera"] = async_add_entities
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
await async_setup_platform(hass, {}, async_add_entities)
|
||||
|
||||
|
||||
class BrowserModCamera(Camera, BrowserModEntity):
|
||||
domain = PLATFORM
|
||||
|
||||
def __init__(self, hass, connection, deviceID, alias=None):
|
||||
class BrowserModCamera(BrowserModEntity, Camera):
|
||||
def __init__(self, coordinator, deviceID):
|
||||
BrowserModEntity.__init__(self, coordinator, deviceID, None)
|
||||
Camera.__init__(self)
|
||||
BrowserModEntity.__init__(self, hass, connection, deviceID, alias)
|
||||
self.last_seen = None
|
||||
|
||||
def updated(self):
|
||||
if self.last_seen is None or (datetime.now() - self.last_seen).seconds > 15:
|
||||
self.last_seen = datetime.now()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def camera_image(self, width=None, height=None):
|
||||
return base64.b64decode(self.data.split(",")[-1])
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"deviceID": self.deviceID,
|
||||
"last_seen": self.last_seen,
|
||||
}
|
||||
def unique_id(self):
|
||||
return f"{self.deviceID}-camera"
|
||||
|
||||
@property
|
||||
def entity_registry_visible_default(self):
|
||||
return True
|
||||
|
||||
def camera_image(self, width=None, height=None):
|
||||
if "camera" not in self._data:
|
||||
LOGGER.error(self._data)
|
||||
return None
|
||||
return base64.b64decode(self._data["camera"].split(",")[-1])
|
||||
|
||||
Reference in New Issue
Block a user