forked from mbachry/mosquitto_pyauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wthermostatbeca.py
59 lines (47 loc) · 1.83 KB
/
wthermostatbeca.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
import mosquitto_pyplugin
class Plugin:
def __init__(self, options):
self._schedules = {}
mosquitto_pyplugin.log(
mosquitto_pyplugin.MOSQ_LOG_INFO,
'Plugin.__init__ (options: {})'.format(options)
)
def plugin_cleanup(self, options):
mosquitto_pyplugin.log(
mosquitto_pyplugin.MOSQ_LOG_INFO,
'Plugin.plugin_cleanup (options: {})'.format(options)
)
def basic_auth(self, client, username, password):
return mosquitto_pyplugin.MOSQ_ERR_SUCCESS
def acl_check(self, client, topic, access, payload):
return mosquitto_pyplugin.MOSQ_ERR_SUCCESS
def message(self, client, message_event):
suffix = '/stat/things/thermostat/schedules'
if (message_event.topic.endswith(suffix) and
message_event.payload != self._schedules.get(
message_event.topic
)):
self._schedules[message_event.topic] = message_event.payload
topic = (message_event.topic[:-len(suffix)] +
'/cmnd/things/thermostat/schedules')
mosquitto_pyplugin.broker_publish(
None,
topic,
message_event.payload,
2,
True,
[],
)
if any(message_event.topic.endswith(t) for t in [
'/cmnd/things/thermostat/properties/deviceOn',
'/cmnd/things/thermostat/properties/mode',
'/cmnd/things/thermostat/properties/targetTemperature',
]):
message_event.retain = True
return mosquitto_pyplugin.MOSQ_ERR_SUCCESS
def plugin_init(options):
mosquitto_pyplugin.log(
mosquitto_pyplugin.MOSQ_LOG_INFO,
'plugin_init (options: {})'.format(options)
)
return Plugin(options)