mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Various updates (#15738)
This commit is contained in:
parent
4013a90f33
commit
681082a3ad
@ -2,56 +2,53 @@
|
|||||||
Proxy camera platform that enables image processing of camera data.
|
Proxy camera platform that enables image processing of camera data.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation
|
For more details about this platform, please refer to the documentation
|
||||||
https://home-assistant.io/components/proxy
|
https://www.home-assistant.io/components/camera.proxy/
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.util.async_ import run_coroutine_threadsafe
|
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||||
|
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME, HTTP_HEADER_HA_AUTH
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
import homeassistant.util.dt as dt_util
|
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_NAME, CONF_ENTITY_ID, HTTP_HEADER_HA_AUTH)
|
|
||||||
from homeassistant.components.camera import (
|
|
||||||
PLATFORM_SCHEMA, Camera)
|
|
||||||
from homeassistant.helpers.aiohttp_client import (
|
from homeassistant.helpers.aiohttp_client import (
|
||||||
async_get_clientsession, async_aiohttp_proxy_web)
|
async_aiohttp_proxy_web, async_get_clientsession)
|
||||||
|
from homeassistant.util.async_ import run_coroutine_threadsafe
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
REQUIREMENTS = ['pillow==5.0.0']
|
REQUIREMENTS = ['pillow==5.2.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_MAX_IMAGE_WIDTH = "max_image_width"
|
CONF_CACHE_IMAGES = 'cache_images'
|
||||||
CONF_IMAGE_QUALITY = "image_quality"
|
CONF_FORCE_RESIZE = 'force_resize'
|
||||||
CONF_IMAGE_REFRESH_RATE = "image_refresh_rate"
|
CONF_IMAGE_QUALITY = 'image_quality'
|
||||||
CONF_FORCE_RESIZE = "force_resize"
|
CONF_IMAGE_REFRESH_RATE = 'image_refresh_rate'
|
||||||
CONF_MAX_STREAM_WIDTH = "max_stream_width"
|
CONF_MAX_IMAGE_WIDTH = 'max_image_width'
|
||||||
CONF_STREAM_QUALITY = "stream_quality"
|
CONF_MAX_STREAM_WIDTH = 'max_stream_width'
|
||||||
CONF_CACHE_IMAGES = "cache_images"
|
CONF_STREAM_QUALITY = 'stream_quality'
|
||||||
|
|
||||||
DEFAULT_BASENAME = "Camera Proxy"
|
DEFAULT_BASENAME = "Camera Proxy"
|
||||||
DEFAULT_QUALITY = 75
|
DEFAULT_QUALITY = 75
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
vol.Optional(CONF_CACHE_IMAGES, False): cv.boolean,
|
||||||
vol.Optional(CONF_MAX_IMAGE_WIDTH): int,
|
vol.Optional(CONF_FORCE_RESIZE, False): cv.boolean,
|
||||||
vol.Optional(CONF_IMAGE_QUALITY): int,
|
vol.Optional(CONF_IMAGE_QUALITY): int,
|
||||||
vol.Optional(CONF_IMAGE_REFRESH_RATE): float,
|
vol.Optional(CONF_IMAGE_REFRESH_RATE): float,
|
||||||
vol.Optional(CONF_FORCE_RESIZE, False): cv.boolean,
|
vol.Optional(CONF_MAX_IMAGE_WIDTH): int,
|
||||||
vol.Optional(CONF_CACHE_IMAGES, False): cv.boolean,
|
|
||||||
vol.Optional(CONF_MAX_STREAM_WIDTH): int,
|
vol.Optional(CONF_MAX_STREAM_WIDTH): int,
|
||||||
|
vol.Optional(CONF_NAME): cv.string,
|
||||||
vol.Optional(CONF_STREAM_QUALITY): int,
|
vol.Optional(CONF_STREAM_QUALITY): int,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_devices,
|
async def async_setup_platform(
|
||||||
discovery_info=None):
|
hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the Proxy camera platform."""
|
"""Set up the Proxy camera platform."""
|
||||||
async_add_devices([ProxyCamera(hass, config)])
|
async_add_devices([ProxyCamera(hass, config)])
|
||||||
|
|
||||||
@ -77,7 +74,7 @@ def _resize_image(image, opts):
|
|||||||
old_size = len(image)
|
old_size = len(image)
|
||||||
if old_width <= new_width:
|
if old_width <= new_width:
|
||||||
if opts.quality is None:
|
if opts.quality is None:
|
||||||
_LOGGER.debug("Image is smaller-than / equal-to requested width")
|
_LOGGER.debug("Image is smaller-than/equal-to requested width")
|
||||||
return image
|
return image
|
||||||
new_width = old_width
|
new_width = old_width
|
||||||
|
|
||||||
@ -86,7 +83,7 @@ def _resize_image(image, opts):
|
|||||||
|
|
||||||
img = img.resize((new_width, new_height), Image.ANTIALIAS)
|
img = img.resize((new_width, new_height), Image.ANTIALIAS)
|
||||||
imgbuf = io.BytesIO()
|
imgbuf = io.BytesIO()
|
||||||
img.save(imgbuf, "JPEG", optimize=True, quality=quality)
|
img.save(imgbuf, 'JPEG', optimize=True, quality=quality)
|
||||||
newimage = imgbuf.getvalue()
|
newimage = imgbuf.getvalue()
|
||||||
if not opts.force_resize and len(newimage) >= old_size:
|
if not opts.force_resize and len(newimage) >= old_size:
|
||||||
_LOGGER.debug("Using original image(%d bytes) "
|
_LOGGER.debug("Using original image(%d bytes) "
|
||||||
@ -94,11 +91,9 @@ def _resize_image(image, opts):
|
|||||||
old_size, len(newimage))
|
old_size, len(newimage))
|
||||||
return image
|
return image
|
||||||
|
|
||||||
_LOGGER.debug("Resized image "
|
_LOGGER.debug(
|
||||||
"from (%dx%d - %d bytes) "
|
"Resized image from (%dx%d - %d bytes) to (%dx%d - %d bytes)",
|
||||||
"to (%dx%d - %d bytes)",
|
old_width, old_height, old_size, new_width, new_height, len(newimage))
|
||||||
old_width, old_height, old_size,
|
|
||||||
new_width, new_height, len(newimage))
|
|
||||||
return newimage
|
return newimage
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +107,7 @@ class ImageOpts():
|
|||||||
self.force_resize = force_resize
|
self.force_resize = force_resize
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
"""Bool evalution rules."""
|
"""Bool evaluation rules."""
|
||||||
return bool(self.max_width or self.quality)
|
return bool(self.max_width or self.quality)
|
||||||
|
|
||||||
|
|
||||||
@ -133,8 +128,7 @@ class ProxyCamera(Camera):
|
|||||||
config.get(CONF_FORCE_RESIZE))
|
config.get(CONF_FORCE_RESIZE))
|
||||||
|
|
||||||
self._stream_opts = ImageOpts(
|
self._stream_opts = ImageOpts(
|
||||||
config.get(CONF_MAX_STREAM_WIDTH),
|
config.get(CONF_MAX_STREAM_WIDTH), config.get(CONF_STREAM_QUALITY),
|
||||||
config.get(CONF_STREAM_QUALITY),
|
|
||||||
True)
|
True)
|
||||||
|
|
||||||
self._image_refresh_rate = config.get(CONF_IMAGE_REFRESH_RATE)
|
self._image_refresh_rate = config.get(CONF_IMAGE_REFRESH_RATE)
|
||||||
@ -145,8 +139,7 @@ class ProxyCamera(Camera):
|
|||||||
self._last_image = None
|
self._last_image = None
|
||||||
self._headers = (
|
self._headers = (
|
||||||
{HTTP_HEADER_HA_AUTH: self.hass.config.api.api_password}
|
{HTTP_HEADER_HA_AUTH: self.hass.config.api.api_password}
|
||||||
if self.hass.config.api.api_password is not None
|
if self.hass.config.api.api_password is not None else None)
|
||||||
else None)
|
|
||||||
|
|
||||||
def camera_image(self):
|
def camera_image(self):
|
||||||
"""Return camera image."""
|
"""Return camera image."""
|
||||||
@ -195,8 +188,8 @@ class ProxyCamera(Camera):
|
|||||||
self.hass, request, stream_coro)
|
self.hass, request, stream_coro)
|
||||||
|
|
||||||
response = aiohttp.web.StreamResponse()
|
response = aiohttp.web.StreamResponse()
|
||||||
response.content_type = ('multipart/x-mixed-replace; '
|
response.content_type = (
|
||||||
'boundary=--frameboundary')
|
'multipart/x-mixed-replace; boundary=--frameboundary')
|
||||||
await response.prepare(request)
|
await response.prepare(request)
|
||||||
|
|
||||||
async def write(img_bytes):
|
async def write(img_bytes):
|
||||||
|
@ -649,7 +649,7 @@ piglow==1.2.4
|
|||||||
pilight==0.1.1
|
pilight==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.camera.proxy
|
# homeassistant.components.camera.proxy
|
||||||
pillow==5.0.0
|
pillow==5.2.0
|
||||||
|
|
||||||
# homeassistant.components.dominos
|
# homeassistant.components.dominos
|
||||||
pizzapi==0.0.3
|
pizzapi==0.0.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user