core/homeassistant/components/camera/demo.py

38 lines
958 B
Python
Raw Normal View History

2015-11-19 18:27:10 +00:00
"""
homeassistant.components.camera.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has a fake camera.
"""
import os
from homeassistant.components.camera import Camera
2015-11-29 07:16:20 +00:00
import homeassistant.util.dt as dt_util
2015-11-19 18:27:10 +00:00
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo camera. """
add_devices([
DemoCamera('Demo camera')
])
class DemoCamera(Camera):
""" A Demo camera. """
def __init__(self, name):
super().__init__()
self._name = name
def camera_image(self):
""" Return a faked still image response. """
2015-11-29 07:16:20 +00:00
now = dt_util.utcnow()
2015-11-19 18:27:10 +00:00
image_path = os.path.join(os.path.dirname(__file__),
2015-11-29 07:16:20 +00:00
'demo_{}.jpg'.format(now.second % 4))
2015-11-19 18:27:10 +00:00
with open(image_path, 'rb') as file:
2015-11-29 02:59:59 +00:00
return file.read()
2015-11-19 18:27:10 +00:00
@property
def name(self):
""" Return the name of this device. """
return self._name