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)"
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"
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"'
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"
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"), )
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"
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())
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())
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)
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