Skip to content

Commit

Permalink
Fix TestMultiAdmin to run on chip-repl based yamltest (#24919)
Browse files Browse the repository at this point in the history
* Fix TestMultiAdmin to run on chip-repl based yamltest

* Restyle

* Address PR comment

* Restyle

* Restyle

* Fix CI test
  • Loading branch information
tehampson authored and pull[bot] committed Jan 24, 2024
1 parent 72c3c1e commit 2256136
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 0 additions & 1 deletion scripts/tests/chiptest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def _GetInDevelopmentTests() -> Set[str]:
"TestEvents.yaml",

"TestGroupMessaging.yaml", # Needs group support in repl
"TestMultiAdmin.yaml", # chip-repl hang on command expeted to fail
}


Expand Down
5 changes: 5 additions & 0 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ void pychip_DeviceController_SetLogFilter(uint8_t category)
PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator,
uint32_t setupPINCode, chip::NodeId nodeid)
{
sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->PairDevice(nodeid,
chip::RendezvousParameters()
.SetPeerAddress(Transport::PeerAddress(Transport::Type::kBle))
Expand All @@ -369,12 +370,14 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission
addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr);
params.SetPeerAddress(addr).SetDiscriminator(0);

sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->PairDevice(nodeid, params, sCommissioningParameters));
}

PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
chip::NodeId nodeid)
{
sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters));
}

Expand Down Expand Up @@ -467,6 +470,7 @@ PyChipError pychip_DeviceController_EstablishPASESessionIP(chip::Controller::Dev
VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT));
addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr);
params.SetPeerAddress(addr).SetDiscriminator(0);
sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, params));
}

Expand All @@ -477,6 +481,7 @@ PyChipError pychip_DeviceController_EstablishPASESessionBLE(chip::Controller::De
RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode);
addr.SetTransportType(chip::Transport::Type::kBle);
params.SetPeerAddress(addr).SetDiscriminator(discriminator);
sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, params));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,34 @@ void ScriptDevicePairingDelegate::SetCommissioningStatusUpdateCallback(
mOnCommissioningStatusUpdateCallback = callback;
}

void ScriptDevicePairingDelegate::OnStatusUpdate(DevicePairingDelegate::Status status)
{
switch (status)
{
case DevicePairingDelegate::Status::SecurePairingSuccess:
ChipLogProgress(Zcl, "Secure Pairing Success");
break;
case DevicePairingDelegate::Status::SecurePairingFailed:
ChipLogError(Zcl, "Secure Pairing Failed");
if (mOnPairingCompleteCallback != nullptr && expectingPairingComplete)
{
// Incorrect state is the same error that chip-tool sends. We are also
// leveraging the on pairing complete callback to indicate that pairing
// has failed.
expectingPairingComplete = false;
mOnPairingCompleteCallback(ToPyChipError(CHIP_ERROR_INCORRECT_STATE));
}
break;
case DevicePairingDelegate::Status::SecurePairingDiscoveringMoreDevices:
break;
}
}

void ScriptDevicePairingDelegate::OnPairingComplete(CHIP_ERROR error)
{
if (mOnPairingCompleteCallback != nullptr)
if (mOnPairingCompleteCallback != nullptr && expectingPairingComplete)
{
expectingPairingComplete = false;
mOnPairingCompleteCallback(ToPyChipError(error));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega
void SetCommissioningSuccessCallback(DevicePairingDelegate_OnCommissioningSuccessFunct callback);
void SetCommissioningFailureCallback(DevicePairingDelegate_OnCommissioningFailureFunct callback);
void SetCommissioningWindowOpenCallback(DevicePairingDelegate_OnWindowOpenCompleteFunct callback);
void OnStatusUpdate(Controller::DevicePairingDelegate::Status status) override;
void OnPairingComplete(CHIP_ERROR error) override;
void OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err) override;
void OnCommissioningSuccess(PeerId peerId) override;
Expand All @@ -68,6 +69,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega
Callback::Callback<Controller::OnOpenCommissioningWindow> *
GetOpenWindowCallback(Controller::CommissioningWindowOpener * context);
void OnOpenCommissioningWindow(NodeId deviceId, CHIP_ERROR status, SetupPayload payload);
void SetExpectingPairingComplete(bool value) { expectingPairingComplete = value; }

private:
DevicePairingDelegate_OnPairingCompleteFunct mOnPairingCompleteCallback = nullptr;
Expand All @@ -78,6 +80,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega
DevicePairingDelegate_OnCommissioningStatusUpdateFunct mOnCommissioningStatusUpdateCallback = nullptr;
Callback::Callback<Controller::OnOpenCommissioningWindow> mOpenWindowCallback;
Controller::CommissioningWindowOpener * mWindowOpener = nullptr;
bool expectingPairingComplete = false;
};

} // namespace Controller
Expand Down

0 comments on commit 2256136

Please sign in to comment.