classGentecMaestroEnergyMeter(Thing):""" Simple example to implement acquisition loops and events to push the captured data. Customize it for your application or implement your own. """data_point_event=Event(friendly_name='data-point-event',doc='Event raised when a new data point is available',label='Data Point Event')defloop(self):self._run=Truewhileself._run:self._last_measurement=self.current_valuetimestamp=datetime.datetime.now().strftime("%H:%M:%S")self.data_point_event.push(dict(timestamp=timestamp,energy=self._last_measurement))
One can subscribe to the event using the attribute name:
fromhololinked.clientimportObjectProxy# events works also through inter-process communication, apart from TCPenergy_meter_proxy=ObjectProxy(instance_name='gentec-maestro',protocol='IPC')defevent_cb(event_data):print(event_data)energy_meter_proxy.subscribe_event(name='data_point_event',callbacks=event_cb)
One can also supply multiple callbacks which may called in series or threaded:
classGentecMaestroEnergyMeter(Thing):data_point_event_schema={"type":"object","properties":{"timestamp":{"type":"string"},"energy":{"type":"number"}},"required":["timestamp","energy"]}data_point_event=Event(doc='Event raised when a new data point is available',label='Data Point Event',schema=data_point_event_schema)
There is no separate validation on the server side.