예제 #1
0
    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
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 def get_status(self) -> Struct:
     """
     Gets the current system status
     :return: A Struct populated with system state info
     """
     data = Struct(is_open=self.__door_state)
     data.status_text = "OPEN" if data.is_open else "CLOSED"
     data.cpu_temp_c = self.get_cpu_temperature()
     data.cpu_temp_f = data.cpu_temp_c * 9.0 / 5.0 + 32
     data.gpu_temp_c = self.get_gpu_temperature()
     data.gpu_temp_f = data.gpu_temp_c * 9.0 / 5.0 + 32
     data.garage_temp_c = self.get_garage_temperature()
     data.garage_temp_f = data.garage_temp_c * 9.0 / 5.0 + 32
     return data
예제 #5
0
 def get_status(self) -> Struct:
     """
     Gets the current system status
     :return: A Struct populated with system state info
     """
     data = Struct(is_open=self.__door_state)
     data.status_text = "OPEN" if data.is_open else "CLOSED"
     data.cpu_temp_c = self.get_cpu_temperature()
     data.cpu_temp_f = data.cpu_temp_c * 9.0 / 5.0 + 32
     data.gpu_temp_c = self.get_gpu_temperature()
     data.gpu_temp_f = data.gpu_temp_c * 9.0 / 5.0 + 32
     return data