Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
681082a3
Commit
681082a3
authored
6 years ago
by
Fabian Affolter
Committed by
Pascal Vizeli
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Various updates (#15738)
parent
4013a90f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/camera/proxy.py
+32
-39
32 additions, 39 deletions
homeassistant/components/camera/proxy.py
requirements_all.txt
+1
-1
1 addition, 1 deletion
requirements_all.txt
with
33 additions
and
40 deletions
homeassistant/components/camera/proxy.py
+
32
−
39
View file @
681082a3
...
...
@@ -2,56 +2,53 @@
Proxy camera platform that enables image processing of camera data.
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
logging
import
aiohttp
import
async_timeout
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
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
(
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__
)
CONF_
MAX
_IMAGE
_WIDTH
=
"
max_image_width
"
CONF_
IMAGE_QUALITY
=
"
image_quality
"
CONF_IMAGE_
REFRESH_RATE
=
"
image_
refresh_rate
"
CONF_
FORCE_RESIZE
=
"
force_resize
"
CONF_MAX_
STREAM
_WIDTH
=
"
max_
stream
_width
"
CONF_STREAM_
QUALITY
=
"
stream_quality
"
CONF_
CACHE_IMAGES
=
"
cache_images
"
CONF_
CACHE
_IMAGE
S
=
'
cache_images
'
CONF_
FORCE_RESIZE
=
'
force_resize
'
CONF_IMAGE_
QUALITY
=
'
image_
quality
'
CONF_
IMAGE_REFRESH_RATE
=
'
image_refresh_rate
'
CONF_MAX_
IMAGE
_WIDTH
=
'
max_
image
_width
'
CONF_
MAX_
STREAM_
WIDTH
=
'
max_stream_width
'
CONF_
STREAM_QUALITY
=
'
stream_quality
'
DEFAULT_BASENAME
=
"
Camera Proxy
"
DEFAULT_QUALITY
=
75
PLATFORM_SCHEMA
=
PLATFORM_SCHEMA
.
extend
({
vol
.
Required
(
CONF_ENTITY_ID
):
cv
.
entity_id
,
vol
.
Optional
(
CONF_
NAME
):
cv
.
string
,
vol
.
Optional
(
CONF_
MAX_IMAGE_WIDTH
):
int
,
vol
.
Optional
(
CONF_
CACHE_IMAGES
,
False
):
cv
.
boolean
,
vol
.
Optional
(
CONF_
FORCE_RESIZE
,
False
):
cv
.
boolean
,
vol
.
Optional
(
CONF_IMAGE_QUALITY
):
int
,
vol
.
Optional
(
CONF_IMAGE_REFRESH_RATE
):
float
,
vol
.
Optional
(
CONF_FORCE_RESIZE
,
False
):
cv
.
boolean
,
vol
.
Optional
(
CONF_CACHE_IMAGES
,
False
):
cv
.
boolean
,
vol
.
Optional
(
CONF_MAX_IMAGE_WIDTH
):
int
,
vol
.
Optional
(
CONF_MAX_STREAM_WIDTH
):
int
,
vol
.
Optional
(
CONF_NAME
):
cv
.
string
,
vol
.
Optional
(
CONF_STREAM_QUALITY
):
int
,
})
async
def
async_setup_platform
(
hass
,
config
,
async_add_devices
,
discovery_info
=
None
):
async
def
async_setup_platform
(
hass
,
config
,
async_add_devices
,
discovery_info
=
None
):
"""
Set up the Proxy camera platform.
"""
async_add_devices
([
ProxyCamera
(
hass
,
config
)])
...
...
@@ -77,7 +74,7 @@ def _resize_image(image, opts):
old_size
=
len
(
image
)
if
old_width
<=
new_width
:
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
new_width
=
old_width
...
...
@@ -86,7 +83,7 @@ def _resize_image(image, opts):
img
=
img
.
resize
((
new_width
,
new_height
),
Image
.
ANTIALIAS
)
imgbuf
=
io
.
BytesIO
()
img
.
save
(
imgbuf
,
"
JPEG
"
,
optimize
=
True
,
quality
=
quality
)
img
.
save
(
imgbuf
,
'
JPEG
'
,
optimize
=
True
,
quality
=
quality
)
newimage
=
imgbuf
.
getvalue
()
if
not
opts
.
force_resize
and
len
(
newimage
)
>=
old_size
:
_LOGGER
.
debug
(
"
Using original image(%d bytes)
"
...
...
@@ -94,11 +91,9 @@ def _resize_image(image, opts):
old_size
,
len
(
newimage
))
return
image
_LOGGER
.
debug
(
"
Resized image
"
"
from (%dx%d - %d bytes)
"
"
to (%dx%d - %d bytes)
"
,
old_width
,
old_height
,
old_size
,
new_width
,
new_height
,
len
(
newimage
))
_LOGGER
.
debug
(
"
Resized image from (%dx%d - %d bytes) to (%dx%d - %d bytes)
"
,
old_width
,
old_height
,
old_size
,
new_width
,
new_height
,
len
(
newimage
))
return
newimage
...
...
@@ -112,7 +107,7 @@ class ImageOpts():
self
.
force_resize
=
force_resize
def
__bool__
(
self
):
"""
Bool evalution rules.
"""
"""
Bool evalu
a
tion rules.
"""
return
bool
(
self
.
max_width
or
self
.
quality
)
...
...
@@ -133,8 +128,7 @@ class ProxyCamera(Camera):
config
.
get
(
CONF_FORCE_RESIZE
))
self
.
_stream_opts
=
ImageOpts
(
config
.
get
(
CONF_MAX_STREAM_WIDTH
),
config
.
get
(
CONF_STREAM_QUALITY
),
config
.
get
(
CONF_MAX_STREAM_WIDTH
),
config
.
get
(
CONF_STREAM_QUALITY
),
True
)
self
.
_image_refresh_rate
=
config
.
get
(
CONF_IMAGE_REFRESH_RATE
)
...
...
@@ -145,8 +139,7 @@ class ProxyCamera(Camera):
self
.
_last_image
=
None
self
.
_headers
=
(
{
HTTP_HEADER_HA_AUTH
:
self
.
hass
.
config
.
api
.
api_password
}
if
self
.
hass
.
config
.
api
.
api_password
is
not
None
else
None
)
if
self
.
hass
.
config
.
api
.
api_password
is
not
None
else
None
)
def
camera_image
(
self
):
"""
Return camera image.
"""
...
...
@@ -195,8 +188,8 @@ class ProxyCamera(Camera):
self
.
hass
,
request
,
stream_coro
)
response
=
aiohttp
.
web
.
StreamResponse
()
response
.
content_type
=
(
'
multipart/x-mixed-replace;
'
'
boundary=--frameboundary
'
)
response
.
content_type
=
(
'
multipart/x-mixed-replace;
boundary=--frameboundary
'
)
await
response
.
prepare
(
request
)
async
def
write
(
img_bytes
):
...
...
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
1
−
1
View file @
681082a3
...
...
@@ -649,7 +649,7 @@ piglow==1.2.4
pilight==0.1.1
# homeassistant.components.camera.proxy
pillow==5.
0
.0
pillow==5.
2
.0
# homeassistant.components.dominos
pizzapi==0.0.3
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment