def action_request() -> xdlms.ActionRequestNormal: return xdlms.ActionRequestNormal( cosem_method=cosem.CosemMethod( interface=enumerations.CosemInterface.DISCONNECT_CONTROL, instance=cosem.Obis.from_dotted("0.0.96.3.10.255"), method=1, ), data=dlms_data.UnsignedLongData(0).to_bytes(), invoke_id_and_priority=xdlms.InvokeIdAndPriority(invoke_id=1, confirmed=True, high_priority=True), )
def action(self, method: cosem.CosemMethod, data: bytes): self.send(xdlms.ActionRequestNormal(cosem_method=method, data=data)) response = self.next_event() if isinstance(response, xdlms.ActionResponseNormalWithError): raise ActionError(response.error.name) elif isinstance(response, xdlms.ActionResponseNormalWithData): if response.status != enumerations.ActionResultStatus.SUCCESS: raise ActionError(f"Unsuccessful ActionRequest: {response.status.name}") return response.data else: if response.status != enumerations.ActionResultStatus.SUCCESS: raise ActionError(f"Unsuccessful ActionRequest: {response.status.name}") return
def test_transform_bytes_without_data(self): data = b"\xc3\x01\xc0\x00\x0f\x00\x00(\x00\x00\xff\x01\x00" action = xdlms.ActionRequestNormal( cosem_method=cosem.CosemMethod( interface=enumerations.CosemInterface.ASSOCIATION_LN, instance=cosem.Obis(a=0, b=0, c=40, d=0, e=0, f=255), method=1, ), data=None, invoke_id_and_priority=xdlms.InvokeIdAndPriority( invoke_id=0, confirmed=True, high_priority=True), ) assert data == action.to_bytes() assert action == xdlms.ActionRequestNormal.from_bytes(data)
def test_transform_bytes(self): data = b'\xc3\x01\xc0\x00\x0f\x00\x00(\x00\x00\xff\x01\x01\t\x11\x10\x00\x00\x1a\x90\xe6\xd2"\x1f\xa2\xfd\x85\xee\xd6\x1a\xcc"' action = xdlms.ActionRequestNormal( cosem_method=cosem.CosemMethod( interface=enumerations.CosemInterface.ASSOCIATION_LN, instance=cosem.Obis(a=0, b=0, c=40, d=0, e=0, f=255), method=1, ), data= b'\t\x11\x10\x00\x00\x1a\x90\xe6\xd2"\x1f\xa2\xfd\x85\xee\xd6\x1a\xcc"', invoke_id_and_priority=xdlms.InvokeIdAndPriority( invoke_id=0, confirmed=True, high_priority=True), ) assert data == action.to_bytes() assert action == xdlms.ActionRequestNormal.from_bytes(data)