mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Check raspistill exisance and check parameters in setup_platform
This commit is contained in:
parent
bf915cf3b4
commit
65ef836313
1
.Python
Symbolic link
1
.Python
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/System/Library/Frameworks/Python.framework/Versions/2.7/Python
|
@ -3,6 +3,7 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
|
|
||||||
@ -11,8 +12,35 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Raspberry Camera."""
|
"""Setup the Raspberry Camera."""
|
||||||
|
if shutil.which("raspistill") is None:
|
||||||
|
_LOGGER.error("Error: raspistill not found")
|
||||||
|
return None
|
||||||
|
|
||||||
|
horizontal_flip_arg = ""
|
||||||
|
horizontal_flip = int(config.get("horizontal_flip", "0"))
|
||||||
|
if horizontal_flip:
|
||||||
|
horizontal_flip_arg = " -hf "
|
||||||
|
|
||||||
|
vertical_flip_arg = ""
|
||||||
|
vertical_flip = int(config.get("vertical_flip", "0"))
|
||||||
|
if vertical_flip:
|
||||||
|
vertical_flip_arg = " -vf"
|
||||||
|
|
||||||
|
setup_config = (
|
||||||
|
{
|
||||||
|
"name": config.get("name", "Raspberry Pi Camera"),
|
||||||
|
"image_width": int(config.get("image_width", "640")),
|
||||||
|
"image_height": int(config.get("image_height", "480")),
|
||||||
|
"image_quality": int(config.get("image_quality", "7")),
|
||||||
|
"image_rotation": int(config.get("image_rotation", "0")),
|
||||||
|
"timelapse": int(config.get("timelapse", "1000")),
|
||||||
|
"horizontal_flip_arg": horizontal_flip_arg,
|
||||||
|
"vertical_flip_arg": vertical_flip_arg
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
add_devices([
|
add_devices([
|
||||||
RaspberryCamera(config)
|
RaspberryCamera(setup_config)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@ -23,22 +51,7 @@ class RaspberryCamera(Camera):
|
|||||||
"""Initialize Raspberry Pi camera component."""
|
"""Initialize Raspberry Pi camera component."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._name = device_info.get("name", "Raspberry Pi Camera")
|
self._name = device_info["name"]
|
||||||
image_width = int(device_info.get("image_width", "640"))
|
|
||||||
image_height = int(device_info.get("image_height", "480"))
|
|
||||||
image_quality = int(device_info.get("image_quality", "7"))
|
|
||||||
image_rotation = int(device_info.get("image_rotation", "0"))
|
|
||||||
timelapse = int(device_info.get("timelapse", "1000"))
|
|
||||||
|
|
||||||
horizontal_flip_arg = ""
|
|
||||||
horizontal_flip = int(device_info.get("horizontal_flip", "0"))
|
|
||||||
if horizontal_flip:
|
|
||||||
horizontal_flip_arg = " -hf "
|
|
||||||
|
|
||||||
vertical_flip_arg = ""
|
|
||||||
vertical_flip = int(device_info.get("vertical_flip", "0"))
|
|
||||||
if vertical_flip:
|
|
||||||
vertical_flip_arg = " -vf"
|
|
||||||
|
|
||||||
image_path = os.path.join(os.path.dirname(__file__),
|
image_path = os.path.join(os.path.dirname(__file__),
|
||||||
'image.jpg')
|
'image.jpg')
|
||||||
@ -47,12 +60,15 @@ class RaspberryCamera(Camera):
|
|||||||
cmd = 'killall raspistill'
|
cmd = 'killall raspistill'
|
||||||
subprocess.call(cmd, shell=True)
|
subprocess.call(cmd, shell=True)
|
||||||
# start new instance of raspistill
|
# start new instance of raspistill
|
||||||
cmd = ('raspistill --nopreview -o ' + image_path +
|
cmd = ('raspistill --nopreview -o ' + str(image_path) +
|
||||||
' -t 0 ' + '-w ' + str(image_width) + ' -h ' +
|
' -t 0 ' + '-w ' + str(device_info["image_width"]) +
|
||||||
str(image_height) + ' -tl ' + str(timelapse) + ' -q ' +
|
' -h ' + str(device_info["image_height"]) +
|
||||||
str(image_quality) + str(horizontal_flip_arg) +
|
' -tl ' + str(device_info["timelapse"]) +
|
||||||
str(vertical_flip_arg) + ' -rot ' + str(image_rotation) +
|
' -q ' + str(device_info["image_quality"]) +
|
||||||
'&')
|
str(device_info["horizontal_flip_arg"]) +
|
||||||
|
str(device_info["vertical_flip_arg"]) +
|
||||||
|
' -rot ' + str(device_info["image_rotation"]) +
|
||||||
|
' &')
|
||||||
|
|
||||||
subprocess.call(cmd, shell=True)
|
subprocess.call(cmd, shell=True)
|
||||||
|
|
||||||
|
1
include/python2.7
Symbolic link
1
include/python2.7
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
|
Loading…
x
Reference in New Issue
Block a user