core/homeassistant/components/camera/demo.py

41 lines
1.1 KiB
Python
Raw Normal View History

2015-11-19 18:27:10 +00:00
"""
Demo camera platform that has a fake camera.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
2015-11-19 18:27:10 +00:00
"""
import os
2016-02-19 05:27:50 +00:00
2015-11-29 07:16:20 +00:00
import homeassistant.util.dt as dt_util
2016-02-19 05:27:50 +00:00
from homeassistant.components.camera import Camera
2015-11-19 18:27:10 +00:00
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Demo camera platform."""
2015-11-19 18:27:10 +00:00
add_devices([
DemoCamera('Demo camera')
])
class DemoCamera(Camera):
"""The representation of a Demo camera."""
2016-03-07 19:29:54 +00:00
2015-11-19 18:27:10 +00:00
def __init__(self, name):
2016-03-07 19:29:54 +00:00
"""Initialize demo camera component."""
2015-11-19 18:27:10 +00:00
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 camera."""
2015-11-19 18:27:10 +00:00
return self._name