-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
AliceSatellite.py
78 lines (50 loc) · 2.03 KB
/
AliceSatellite.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
71
72
73
74
75
76
77
78
from core.base.SuperManager import SuperManager
from core.base.model.AliceSkill import AliceSkill
from core.dialog.model.DialogSession import DialogSession
from core.util.Decorators import MqttHandler
class AliceSatellite(AliceSkill):
def __init__(self):
self._sensorReadings = dict()
super().__init__()
def onBooted(self):
confManager = SuperManager.getInstance().ConfigManager
if confManager.configAliceExists('onReboot') and confManager.getAliceConfigByName('onReboot') == 'greetAndRebootDevices':
self.MqttManager.mqttBroadcast(
topic='projectalice/devices/restart'
)
def onSleep(self):
self.publish('projectalice/devices/sleep')
def onWakeup(self):
self.publish('projectalice/devices/wakeup')
def onGoingBed(self):
self.publish('projectalice/devices/goingBed')
def onFullMinute(self):
self.getSensorReadings()
@MqttHandler('projectalice/devices/sensorsFeedback')
def feedbackSensorIntent(self, session: DialogSession):
data = session.payload.get('data')
if data:
self._sensorReadings[session.sessionId] = data
@MqttHandler('projectalice/devices/disconnection')
def deviceDisconnectIntent(self, session: DialogSession):
uid = session.payload.get('uid')
if uid:
self.DeviceManager.deviceDisconnecting(uid)
@MqttHandler('projectalice/devices/status')
def deviceStatus(self, session: DialogSession):
uid = session.payload.get('uid')
device = self.DeviceManager.getDevice(uid=uid)
refresh = False
if device.skillName != self.name:
return
if 'dnd' in session.payload:
device.updateParam('dnd', session.payload.get('dnd', None))
refresh = True
if refresh:
self.publish('projectalice/devices/updated', payload={'id': device.id, 'type': 'status'})
def getSensorReadings(self):
self.publish('projectalice/devices/alice/getSensors')
def temperatureAt(self, deviceUid: str) -> str:
return self.getSensorValue(deviceUid, 'temperature')
def getSensorValue(self, deviceUid: str, value: str) -> str:
return self._sensorReadings.get(deviceUid, dict()).get(value, 'undefined')