Example #1
0
 def test_invalid_command_type_raises_value_error(self):
     with pytest.raises(ValueError):
         cm = messages.CommandMessage(
             command="R",
             command_type="12",
             data_set=messages.DataSet(address="1.8.0", value="1"),
         )
Example #2
0
    def test_to_representation_without_data_set(self):
        # like the break command

        break_msg = messages.CommandMessage(
            command="B", command_type="0", data_set=None
        )

        assert break_msg.to_representation() == "\x01B0\x03q"
Example #3
0
    def test_command_message_to_representation(self):
        cm = messages.CommandMessage(
            command="R",
            command_type="1",
            data_set=messages.DataSet(address="1.8.0", value="1"),
        )

        assert cm.to_representation() == "\x01R1\x021.8.0(1)\x03k"
Example #4
0
 def send_break(self):
     """
     Sending the break message to indicate that one wants to stop the
     communication.
     """
     logger.info("Sending BREAK message to end communication")
     break_msg = messages.CommandMessage(command="B",
                                         command_type="0",
                                         data_set=None)
     self.transport.send(break_msg.to_bytes())
Example #5
0
 def send_password(self, password=None):
     """
     On receiving the password challenge request one must handle the password
     challenge according to device specification and then send the password.
     :param password:
     """
     _pw = password or self.password
     data_set = messages.DataSet(value=_pw)
     cmd = messages.CommandMessage(command="P", command_type="1", data_set=data_set)
     logger.info("Sending password to meter")
     self.transport.send(cmd.to_bytes())
Example #6
0
    def _send_profile_request(self, start_date: date, end_date: date):
        """
        Send profile request between dates
        """
        # Set format for Luna
        if self.manufacturer_id == "LUN":
            start_date_ = f"{start_date.year % 100}{start_date.month:02d}{start_date.day:02d}"
            end_date_ = f"{end_date.year % 100}{end_date.month:02d}{end_date.day:02d}"
        elif self.manufacturer_id == "MSY":  # Set format for makel
            start_date_ = f"{start_date.year % 100}{start_date.month:02d}{start_date.day:02d}0000"
            end_date_ = f"{end_date.year % 100}{end_date.month:02d}{end_date.day:02d}0000"

        command = "R"
        command_type = "5" if self.manufacturer_id == "LUN" else "2"
        address = "P1" if self.manufacturer_id == "LUN" else "P.01"
        end = "" if self.manufacturer_id == "LUN" else None

        cmd = messages.CommandMessage(command=command, command_type=command_type,
                                      data_set=messages.DataSet(value=f"{start_date_};{end_date_}", address=address, end=end))
        logger.info(f"Sending profile request to meter. {cmd.to_bytes()}")
        self.transport.send(cmd.to_bytes())