1
|
|
|
|
2
|
|
|
import backend.fcmservice |
3
|
|
|
#from backend.fcmservice import BaseService |
4
|
|
|
from helpers.camerahelper import take_picture |
5
|
|
|
from domain.sensors import SensorValue |
6
|
|
|
|
7
|
|
|
class CameraService(backend.fcmservice.BaseService): |
8
|
|
|
#def __init__(self, config, cache): |
9
|
|
|
# super(CameraService, config, cache) |
10
|
|
|
|
11
|
|
|
def take_picture(self, file_name='fullcycle_camera.png'): |
12
|
|
|
pic = take_picture(file_name, |
13
|
|
|
super().configuration.get('camera.size'), |
14
|
|
|
super().configuration.get('camera.quality'), |
15
|
|
|
super().configuration.get('camera.brightness'), |
16
|
|
|
super().configuration.get('camera.contrast')) |
17
|
|
|
return pic |
18
|
|
|
|
19
|
|
|
def store_picture_cache(self, file_name): |
20
|
|
|
if os.path.isfile(file_name): |
|
|
|
|
21
|
|
|
with open(file_name, 'rb') as photofile: |
22
|
|
|
picdata = photofile.read() |
23
|
|
|
#picture will be handled like a sensor |
24
|
|
|
reading = SensorValue('fullcyclecamera', base64.b64encode(picdata), 'camera') |
|
|
|
|
25
|
|
|
message = super().createmessageenvelope() |
26
|
|
|
sensorjson = message.jsonserialize(SensorValueSchema(), reading) |
|
|
|
|
27
|
|
|
self.cache.tryputcache(CacheKeys.camera, sensorjson) |
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|