forked from rimram31/dz_smarthome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.py
55 lines (41 loc) · 1.72 KB
/
lambda.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
import json
import logging
import AlexaSmartHome, DomoticzHandler
logger = logging.getLogger()
class Configuration(object):
def __init__(self, filename=None, optsDict=None):
self._json = {}
if filename is not None:
with open(filename) as f:
self._json = json.load(f)
if optsDict is not None:
self._json = optsDict
opts = {}
opts['url'] = self.get(['url'], default='http://localhost/')
opts['username'] = self.get(['username'], default='')
opts['password'] = self.get(['password'], default='')
opts['includeScenesGroups'] = self.get(['includeScenesGroups'], default=False)
opts['planID'] = self.get(['planID'], default=None)
opts['prefixName'] = self.get(['prefixName'], default=None)
opts['debug'] = self.get(['debug'], default=False)
self.opts = opts
def __getattr__(self, name):
return self.opts[name]
def get(self, keys, default):
for key in keys:
if key in self._json:
return self._json[key]
return default
def dump(self):
return json.dumps(self.opts, indent=2, separators=(',', ': '))
def event_handler(request, context):
config = Configuration('configdz.json')
if config.debug:
logger.setLevel(logging.DEBUG)
logger.debug("Lambda invocation %s", repr(request))
dzRemote = DomoticzHandler.Domoticz(config.url, config.username, config.password)
dzRemote.configure(config)
response = AlexaSmartHome.handle_message(dzRemote, request)
logger.debug("Skill response %s", response)
return response
# aws lambda update-function-configuration --function-name Alexicz --handler "lambda.event_handler"