示例#1
0
 def received_message(self, message):
     if not hasattr(self, 'metadata'):
         return
     allowed_types = [
         GatewayEvent.Types.OUTPUT_CHANGE,
         GatewayEvent.Types.THERMOSTAT_CHANGE,
         GatewayEvent.Types.THERMOSTAT_GROUP_CHANGE,
         GatewayEvent.Types.SHUTTER_CHANGE, GatewayEvent.Types.INPUT_CHANGE
     ]
     try:
         data = msgpack.loads(message.data)
         event = GatewayEvent.deserialize(data)
         if event.type == GatewayEvent.Types.ACTION:
             if event.data['action'] == 'set_subscription':
                 subscribed_types = [
                     stype for stype in event.data['types']
                     if stype in allowed_types
                 ]
                 cherrypy.engine.publish(
                     'update-events-receiver', self.metadata['client_id'],
                     {'subscribed_types': subscribed_types})
         elif event.type == GatewayEvent.Types.PING:
             self.send(msgpack.dumps(
                 GatewayEvent(event_type=GatewayEvent.Types.PONG,
                              data=None).serialize()),
                       binary=True)
     except Exception as ex:
         logger.exception('Error receiving message: %s', ex)
示例#2
0
 def _handle_input_status(self, data, data_type='status'):
     event = GatewayEvent.deserialize(
         data) if data_type == 'event' else None
     for decorated_method in self._decorated_methods['input_status']:
         decorator_version = decorated_method.input_status.get('version', 1)
         if decorator_version not in PluginRuntime.SUPPORTED_DECORATOR_VERSIONS[
                 'input_status']:
             error = NotImplementedError(
                 'Version {} is not supported for input status decorators'.
                 format(decorator_version))
             self._writer.log_exception('input status', error)
         else:
             if decorator_version == 1 and data_type == 'status':
                 self._writer.with_catch('input status', decorated_method,
                                         [data])
             elif decorator_version == 2 and event is not None:
                 # get relevant event details
                 input_id = event.data['id']
                 status = event.data['status']
                 # Version 2 will send ALL input status changes AND in a dict format
                 self._writer.with_catch('input status', decorated_method,
                                         [{
                                             'input_id': input_id,
                                             'status': status
                                         }])
示例#3
0
 def _handle_output_status(self, data, data_type='status'):
     event = GatewayEvent.deserialize(
         data) if data_type == 'event' else None
     for receiver in self._decorated_methods['output_status']:
         decorator_version = receiver.output_status.get('version', 1)
         if decorator_version not in PluginRuntime.SUPPORTED_DECORATOR_VERSIONS[
                 'output_status']:
             error = NotImplementedError(
                 'Version {} is not supported for output status decorators'.
                 format(decorator_version))
             self._writer.log_exception('output status', error)
         else:
             if decorator_version == 1 and data_type == 'status':
                 self._writer.with_catch('output status', receiver, [data])
             elif decorator_version == 2 and event:
                 self._writer.with_catch('output status', receiver,
                                         [event.data])
示例#4
0
 def _handle_input_status(self, data):
     event = GatewayEvent.deserialize(data)
     # get relevant event details
     input_id = event.data['id']
     status = event.data['status']
     for decorated_method in self._decorated_methods['input_status']:
         decorator_version = decorated_method.input_status.get('version', 1)
         if decorator_version == 1:
             # Backwards compatibility: only send rising edges of the input (no input releases)
             if status:
                 self._writer.with_catch('input status', decorated_method,
                                         [(input_id, None)])
         elif decorator_version == 2:
             # Version 2 will send ALL input status changes AND in a dict format
             self._writer.with_catch('input status', decorated_method,
                                     [{
                                         'input_id': input_id,
                                         'status': status
                                     }])
         else:
             error = NotImplementedError(
                 'Version {} is not supported for input status decorators'.
                 format(decorator_version))
             self._writer.log_exception('input status', error)
示例#5
0
 def _handle_thermostat_group_status(self, data):
     event = GatewayEvent.deserialize(data)
     for receiver in self._decorated_methods['thermostat_group_status']:
         self._writer.with_catch('thermostat group status', receiver,
                                 [event.data])
示例#6
0
 def _handle_ventilation_status(self, data):
     event = GatewayEvent.deserialize(data)
     for receiver in self._decorated_methods['ventilation_status']:
         self._writer.with_catch('ventilation status', receiver,
                                 [event.data])