Exemplo n.º 1
0
    def test_to_representation(self):
        dl = messages.DataLine(data_sets=[
            messages.DataSet(address="3:14", value="314", unit="kWh"),
            messages.DataSet(address="4:15", value="415", unit="kWh"),
        ])

        rep = dl.to_representation()

        assert rep == "3:14(314*kWh)4:15(415*kWh)"
Exemplo n.º 2
0
        def test_to_representation_single_line(self):
            db = messages.DataBlock(data_lines=[
                messages.DataLine(data_sets=[
                    messages.DataSet(address="3:14", value="314", unit="kWh"),
                    messages.DataSet(address="4:15", value="415", unit="kWh"),
                ])
            ])

            assert db.to_representation() == "3:14(314*kWh)4:15(415*kWh)\r\n"
Exemplo n.º 3
0
    def test_to_representation(self):
        rdm = messages.ReadoutDataMessage(data_block=messages.DataBlock(
            data_lines=[
                messages.DataLine(data_sets=[
                    messages.DataSet(address="3:14", value="314", unit="kWh"),
                    messages.DataSet(address="4:15", value="415", unit="kWh"),
                ])
            ]))

        assert rdm.to_representation(
        ) == '\x023:14(314*kWh)4:15(415*kWh)\r\n!\r\n\x03"'
Exemplo n.º 4
0
    def test_to_representation(self):
        db = messages.DataBlock(data_lines=[
            messages.DataLine(data_sets=[
                messages.DataSet(address="3:14", value="314", unit="kWh"),
                messages.DataSet(address="4:15", value="415", unit="kWh"),
            ])
        ])

        am = messages.AnswerDataMessage(data_block=db)

        assert am.to_representation(
        ) == "\x023:14(314*kWh)4:15(415*kWh)\r\n\x03\x04"
Exemplo n.º 5
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"),
         )
Exemplo n.º 6
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"
Exemplo n.º 7
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())
Exemplo n.º 8
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())
Exemplo n.º 9
0
 def test_to_byte_without_unit(self):
     ds = messages.DataSet(value="100", address="3.1.0", unit=None)
     assert ds.to_bytes() == self.data_set_without_unit.encode(constants.ENCODING)
Exemplo n.º 10
0
 def test_to_string_without_unit(self):
     ds = messages.DataSet(value="100", address="3.1.0", unit=None)
     assert ds.to_representation() == self.data_set_without_unit