def with_pre_established_association( cls, conformance: Conformance, max_pdu_size: int = 65535, global_encryption_key: Optional[bytes] = None, global_authentication_key: Optional[bytes] = None, client_invocation_counter: Optional[int] = None, meter_invocation_counter: Optional[int] = None, client_system_title: Optional[bytes] = None, meter_system_title: Optional[bytes] = None, ): """ A pre-established association does not need the ACSE APDUs. It is predetermined what access the client have. """ return cls( client_system_title=client_system_title, meter_system_title=meter_system_title, global_encryption_key=global_encryption_key, global_authentication_key=global_authentication_key, meter_invocation_counter=meter_invocation_counter, client_invocation_counter=client_invocation_counter, # Moves the state into ready. state=dlms_state.DlmsConnectionState( current_state=dlms_state.READY), is_pre_established=True, conformance=conformance, max_pdu_size=max_pdu_size, )
def test_can_send_get_when_ready(get_request: xdlms.GetRequestNormal): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.READY), client_system_title=b"12345678", ) c.send(get_request) assert c.state.current_state == state.AWAITING_GET_RESPONSE
def test_receive_get_response_sets_state_to_ready(): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.AWAITING_GET_RESPONSE), client_system_title=b"12345678", ) c.receive_data(b"\xc4\x01\xc1\x00\x06\x00\x00\x13\x91") c.next_event() assert c.state.current_state == state.READY
def test_can_release_in_ready_state(rlrq: acse.ReleaseRequest): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.READY), client_system_title=b"12345678", ) c.send(rlrq) assert c.state.current_state == state.AWAITING_RELEASE_RESPONSE
def test_receive_rlre_terminates_association(rlre: acse.ReleaseResponse): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.AWAITING_RELEASE_RESPONSE), client_system_title=b"12345678", ) c.receive_data(rlre.to_bytes()) c.next_event() assert c.state.current_state == state.NO_ASSOCIATION
def test_can_send_action_request_in_ready(action_request: xdlms.ActionRequestNormal): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.READY), client_system_title=b"12345678", ) c.send(action_request) assert c.state.current_state == state.AWAITING_ACTION_RESPONSE
def test_cannot_re_associate(aarq: acse.ApplicationAssociationRequest): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.READY), client_system_title=b"12345678", ) with pytest.raises(LocalDlmsProtocolError): c.send(aarq)
def test_aare_sets_ready_on_waiting_aare_response(): s = state.DlmsConnectionState(current_state=state.AWAITING_ASSOCIATION_RESPONSE) s.process_event( acse.ApplicationAssociationResponseApdu( enumerations.AssociationResult.ACCEPTED, result_source_diagnostics=enumerations.AcseServiceUserDiagnostics.NULL, ) ) assert s.current_state == state.READY
def test_set_response_sets_state_in_ready(set_response: xdlms.SetResponseNormal): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.AWAITING_SET_RESPONSE), client_system_title=b"12345678", ) c.receive_data(set_response.to_bytes()) c.next_event() assert c.state.current_state == state.READY
def test_set_request_sets_state_in_waiting_for_set_response( set_request: xdlms.SetRequestNormal, ): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.READY), client_system_title=b"12345678", ) c.send(set_request) assert c.state.current_state == state.AWAITING_SET_RESPONSE
def test_aarq_makes_dlms_waiting_for_aare(): s = state.DlmsConnectionState() s.process_event( acse.ApplicationAssociationRequestApdu( user_information=UserInformation( InitiateRequestApdu(proposed_conformance=Conformance()) ) ) ) assert s.current_state == state.AWAITING_ASSOCIATION_RESPONSE
def test_receive_exception_response_sets_state_to_ready( exception_response: xdlms.ExceptionResponse, ): c = DlmsConnection( state=state.DlmsConnectionState(current_state=state.AWAITING_GET_RESPONSE), client_system_title=b"12345678", ) c.receive_data(exception_response.to_bytes()) c.next_event() assert c.state.current_state == state.READY
def test_action_response_normal_sets_ready_when_awaiting_action_resoponse(): c = DlmsConnection( state=state.DlmsConnectionState( current_state=state.AWAITING_ACTION_RESPONSE), client_system_title=b"12345678", ) c.receive_data( xdlms.ActionResponseNormal( status=enumerations.ActionResultStatus.SUCCESS, invoke_id_and_priority=xdlms.InvokeIdAndPriority( invoke_id=1, confirmed=True, high_priority=True), ).to_bytes()) c.next_event() assert c.state.current_state == state.READY
def with_pre_established_association( cls, conformance: Conformance, max_pdu_size: int = 65535, global_encryption_key: Optional[bytes] = None, use_dedicated_ciphering: bool = False, client_system_title: Optional[bytes] = None, ): """ A pre-established association does not need the ACSE APDUs. It is predetermined what access the client have. """ return cls( client_system_title=client_system_title, global_encryption_key=global_encryption_key, # Moves the state into ready. state=dlms_state.DlmsConnectionState( current_state=dlms_state.READY), is_pre_established=True, conformance=conformance, max_pdu_size=max_pdu_size, use_dedicated_ciphering=use_dedicated_ciphering, )
def test_non_aarq_on_initial_raises_protocol_error(): s = state.DlmsConnectionState() with pytest.raises(LocalDlmsProtocolError): s.process_event(acse.ReleaseResponse())