def get_history(self): """ Get the history entries for delivery to the remote server. Get the history entries, formatted as Structs in order to send to a frontend server on a different machine. Returns: An list of json strings (as bytes), with one history entry per item. For example: [ b'{ "description": "Door state changed to OPEN.", "event": "SwitchActivated", "timestamp": "2017-03-21 18:04:12"}', b'{ "description": "Door state changed to CLOSED.", "event": "SwitchActivated", "timestamp": "2017-03-21 18:03:39"}', b'{ "description": "Door state changed to OPEN.", "event": "SensorTrip", "timestamp": "2017-03-21 18:03:39"} ] """ entries = self.__db.read_history() history = [] for entry in entries: data = Struct(timestamp=entry['timestamp'], event=entry['event'], description=entry['description']) history.append(data.to_json_bytes()) return history
def trigger_relay(self, user_agent: str, login: str): self.__logger.debug("Requesting 'trigger_relay'") data = Struct(user_agent=user_agent, login=login) msg_json = data.to_json_bytes() msg = ['trigger_relay', msg_json] reply_json = self.__send_recv_msg(msg) if reply_json is None: return None return json.loads(reply_json)
def trigger_relay(self, user_agent: str, login: str): self.__logger.debug("Requesting 'trigger_relay'") data = Struct(user_agent=user_agent, login=login) msg_json = data.to_json_bytes() msg = ['trigger_relay', msg_json] reply_json = self.__send_recv_msg(msg) if reply_json is None: return None return json.loads(reply_json)