32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
|
import nagios
|
||
|
import socket_protocol
|
||
|
# from devdi.topic import topic_by_props
|
||
|
|
||
|
DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
|
||
|
|
||
|
|
||
|
class server(socket_protocol.pure_json_protocol):
|
||
|
def __init__(self, *args, **kwargs):
|
||
|
if 'devices' in kwargs:
|
||
|
self.__devices__ = kwargs.pop('devices')
|
||
|
socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
|
||
|
#
|
||
|
# self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE),
|
||
|
# DID_FOLLOWS_HEATING_SETPOINT, 'current_heating_setpoint')
|
||
|
#
|
||
|
if not self.__comm_inst__.IS_CLIENT:
|
||
|
self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, self.follow_heating_setpoint)
|
||
|
|
||
|
def follow_heating_setpoint(self, msg):
|
||
|
if msg.get_status() == socket_protocol.STATUS_OKAY:
|
||
|
try:
|
||
|
dev = self.__devices__.get_str(**msg.get_data())
|
||
|
except:
|
||
|
return socket_protocol.STATUS_CALLBACK_ERROR, {"status": nagios.Nagios.UNKNOWN, "msg": "Exception while getting device."}
|
||
|
if dev is None:
|
||
|
return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
|
||
|
else:
|
||
|
return socket_protocol.STATUS_OKAY, dev.status(msg.get_data_id())
|
||
|
else:
|
||
|
return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, {"status": nagios.Nagios.UNKNOWN, "msg": "Socket protocol error."}
|