-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
70 lines (53 loc) · 1.78 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""camera -- interface with video cameras in idiotic
"""
import logging
import requests
from idiotic import utils, item
MODULE_NAME = "camera"
log = logging.getLogger("module.camera")
DRIVERS = {}
CREDENTIALS = None
def configure(config, api, assets):
global CREDENTIALS
CREDENTIALS = config['credentials']
log.info('Drivers loaded: {}'.format(DRIVERS))
def register(c, name):
global DRIVERS
if name in DRIVERS:
log.warn('driver {} declared twice, {} replacing {}'.format(
name, c, DRIVERS[name]))
DRIVERS[name] = c
class Camera(item.BaseItem):
class UnknownCredentialsError(Exception): pass
class UnsupportedCameraError(Exception): pass
def __init__(self, name, uri, driver, *args, credentials_name=None, **kwargs):
super().__init__(name, *args, **kwargs)
self.uri = uri
if credentials_name:
try:
credentials = CREDENTIALS[credentials_name]
except KeyError:
raise UnknownCredentialsError(credentials_name)
else:
credentials = None
if driver not in DRIVERS:
raise UnsupportedCameraError(driver)
else:
self.driver = DRIVERS[driver](uri, credentials)
@item.command
def snapshot(self):
self.driver.get_still()
class CameraDriver:
def __init__(self):
pass
class FI8910EDriver(CameraDriver):
def __init__(self, uri, credentials = None):
self.uri = uri
self.credentials = credentials
def _auth(self):
return {'user': self.credentials['username'],
'pwd': self.credentials['password']}
def get_still(self):
log.info(requests.get(self.uri + '/snapshot.cgi',
params = self._auth()))
register(FI8910EDriver, 'FI8910E')