mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Add camera to demo
This commit is contained in:
parent
aec25c88b4
commit
2cbfc60679
@ -46,7 +46,6 @@ the password for accessing your camera
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
from homeassistant.components.camera import DOMAIN
|
from homeassistant.components.camera import DOMAIN
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
@ -58,7 +57,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Adds a generic IP Camera. """
|
""" Adds a generic IP Camera. """
|
||||||
if not validate_config({DOMAIN: config}, {DOMAIN: ['still_image_url']}, _LOGGER):
|
if not validate_config({DOMAIN: config}, {DOMAIN: ['still_image_url']},
|
||||||
|
_LOGGER):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
add_devices_callback([GenericCamera(config)])
|
add_devices_callback([GenericCamera(config)])
|
||||||
@ -75,15 +75,14 @@ class GenericCamera(Camera):
|
|||||||
self._name = device_info.get('name', 'Generic Camera')
|
self._name = device_info.get('name', 'Generic Camera')
|
||||||
self._username = device_info.get('username')
|
self._username = device_info.get('username')
|
||||||
self._password = device_info.get('password')
|
self._password = device_info.get('password')
|
||||||
|
self._still_image_url = device_info['still_image_url']
|
||||||
self._still_image_url += device_info.get('still_image_url', 'image.jpg')
|
|
||||||
|
|
||||||
def camera_image(self):
|
def camera_image(self):
|
||||||
""" Return a still image reponse from the camera """
|
""" Return a still image reponse from the camera """
|
||||||
if self._username and self._password:
|
if self._username and self._password:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
self._still_image_url,
|
self._still_image_url,
|
||||||
auth=HTTPBasicAuth(self._username,self._password))
|
auth=HTTPBasicAuth(self._username, self._password))
|
||||||
else:
|
else:
|
||||||
response = requests.get(self._still_image_url)
|
response = requests.get(self._still_image_url)
|
||||||
|
|
||||||
|
@ -51,6 +51,15 @@ def setup(hass, config):
|
|||||||
group.setup_group(hass, 'living room', [lights[0], lights[1], switches[0]])
|
group.setup_group(hass, 'living room', [lights[0], lights[1], switches[0]])
|
||||||
group.setup_group(hass, 'bedroom', [lights[2], switches[1]])
|
group.setup_group(hass, 'bedroom', [lights[2], switches[1]])
|
||||||
|
|
||||||
|
# Setup IP Camera
|
||||||
|
bootstrap.setup_component(
|
||||||
|
hass, 'camera',
|
||||||
|
{'camera': {
|
||||||
|
'platform': 'generic',
|
||||||
|
'name': 'IP Camera',
|
||||||
|
'still_image_url': 'http://194.218.96.92/jpg/image.jpg',
|
||||||
|
}})
|
||||||
|
|
||||||
# Setup scripts
|
# Setup scripts
|
||||||
bootstrap.setup_component(
|
bootstrap.setup_component(
|
||||||
hass, 'script',
|
hass, 'script',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user