Skip to content

Commit

Permalink
Update rvc op state in all clusters (#31763)
Browse files Browse the repository at this point in the history
* Updated the all-clusters-app to change the operataional state from the rvc run mode change-to-mode command. Updated the CI pics file to match the capabilities of the all-clutsers-app.

* Updated TC_RVCOPSTATE_2_1 to take the --endpoind flag and fix an execution issue.

* Updated TC_RVCOPSTATE_2_3 to error if the --endpoind flag is not defined and fix an execution issue.

* Updated TC_RVCOPSTATE_2_4 to error if the --endpoind flag is not defined and fixed some execution issues.

* Restyled by whitespace

* Restyled by clang-format

* Restyled by autopep8

* Added the GoHome command PICS, RVCOPSTATE.S.C128.Rsp, to the PICS.yaml.

* fixed typo.

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
hicklin and restyled-commits authored Jan 31, 2024
1 parent c4b5df9 commit 0bd5786
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 70 deletions.
17 changes: 14 additions & 3 deletions examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
#include <app-common/zap-generated/attributes/Accessors.h>
#include <rvc-modes.h>
#include <rvc-operational-state-delegate-impl.h>

using namespace chip::app::Clusters;
using namespace chip::app::Clusters::RvcRunMode;
Expand All @@ -40,14 +41,24 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands:
{
uint8_t currentMode = mInstance->GetCurrentMode();

// Our business logic states that we can only switch into the mapping state from the idle state.
if (NewMode == RvcRunMode::ModeMapping && currentMode != RvcRunMode::ModeIdle)
// Our business logic states that we can only switch into a running mode from the idle state.
if (NewMode != RvcRunMode::ModeIdle && currentMode != RvcRunMode::ModeIdle)
{
response.status = to_underlying(ModeBase::StatusCode::kInvalidInMode);
response.statusText.SetValue(chip::CharSpan::fromCharString("Change to the mapping mode is only allowed from idle"));
response.statusText.SetValue(chip::CharSpan::fromCharString("Change to a running mode is only allowed from idle"));
return;
}

auto rvcOpStateInstance = RvcOperationalState::GetRvcOperationalStateInstance();
if (NewMode == RvcRunMode::ModeIdle)
{
rvcOpStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));
}
else
{
rvcOpStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
}

response.status = to_underlying(ModeBase::StatusCode::kSuccess);
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/tests/suites/certification/PICS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9497,6 +9497,9 @@ PICS:
- label: "Does the device implement receiving the Resume command?"
id: RVCOPSTATE.S.C03.Rsp

- label: "Does the device implement receiving the GoHome command?"
id: RVCOPSTATE.S.C128.Rsp

#Commands generated
- label:
"Does the device implement generating the OperationalCommandResponse
Expand Down
32 changes: 17 additions & 15 deletions src/app/tests/suites/certification/ci-pics-values
Original file line number Diff line number Diff line change
Expand Up @@ -2457,26 +2457,27 @@ RVCOPSTATE.S=1
RVCOPSTATE.C=1

#ManuallyControlled
# These are the PICS supported by the all-clusters-app

RVCOPSTATE.S.M.ST_STOPPED=1
RVCOPSTATE.S.M.ST_RUNNING=1
RVCOPSTATE.S.M.ST_PAUSED=1
RVCOPSTATE.S.M.ST_ERROR=1
RVCOPSTATE.S.M.ST_SEEKING_CHARGER=1
RVCOPSTATE.S.M.ST_CHARGING=1
RVCOPSTATE.S.M.ST_DOCKED=1
RVCOPSTATE.S.M.ST_ERROR=0
RVCOPSTATE.S.M.ST_SEEKING_CHARGER=0
RVCOPSTATE.S.M.ST_CHARGING=0
RVCOPSTATE.S.M.ST_DOCKED=0
RVCOPSTATE.S.M.ERR_NO_ERROR=1
RVCOPSTATE.S.M.ERR_UNABLE_TO_START_OR_RESUME=1
RVCOPSTATE.S.M.ERR_UNABLE_TO_COMPLETE_OPERATION=1
RVCOPSTATE.S.M.ERR_COMMAND_INVALID_IN_STATE=1
RVCOPSTATE.S.M.ERR_FAILED_TO_FIND_CHARGING_DOCK=1
RVCOPSTATE.S.M.ERR_STUCK=1
RVCOPSTATE.S.M.ERR_DUST_BIN_MISSING=1
RVCOPSTATE.S.M.ERR_DUST_BIN_FULL=1
RVCOPSTATE.S.M.ERR_WATER_TANK_EMPTY=1
RVCOPSTATE.S.M.ERR_WATER_TANK_MISSING=1
RVCOPSTATE.S.M.ERR_WATER_TANK_LID_OPEN=1
RVCOPSTATE.S.M.ERR_MOP_CLEANING_PAD_MISSING=1
RVCOPSTATE.S.M.ERR_UNABLE_TO_START_OR_RESUME=0
RVCOPSTATE.S.M.ERR_UNABLE_TO_COMPLETE_OPERATION=0
RVCOPSTATE.S.M.ERR_COMMAND_INVALID_IN_STATE=0
RVCOPSTATE.S.M.ERR_FAILED_TO_FIND_CHARGING_DOCK=0
RVCOPSTATE.S.M.ERR_STUCK=0
RVCOPSTATE.S.M.ERR_DUST_BIN_MISSING=0
RVCOPSTATE.S.M.ERR_DUST_BIN_FULL=0
RVCOPSTATE.S.M.ERR_WATER_TANK_EMPTY=0
RVCOPSTATE.S.M.ERR_WATER_TANK_MISSING=0
RVCOPSTATE.S.M.ERR_WATER_TANK_LID_OPEN=0
RVCOPSTATE.S.M.ERR_MOP_CLEANING_PAD_MISSING=0

#Events
RVCOPSTATE.S.E00=1
Expand All @@ -2496,6 +2497,7 @@ RVCOPSTATE.S.C01.Rsp=0
RVCOPSTATE.S.C02.Rsp=0
RVCOPSTATE.S.C03.Rsp=1
RVCOPSTATE.S.C04.Tx=1
RVCOPSTATE.S.C128.Rsp=1
RVCOPSTATE.C.C00.Tx=1
RVCOPSTATE.C.C01.Tx=1
RVCOPSTATE.C.C02.Tx=1
Expand Down
21 changes: 7 additions & 14 deletions src/python_testing/TC_RVCOPSTATE_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts

# This test requires several additional command line arguments
# run with
# --int-arg PIXIT_ENDPOINT:<endpoint>


class TC_RVCOPSTATE_2_1(MatterBaseTest):
def __init__(self, *args):
super().__init__(*args)
self.endpoint = None

async def read_mod_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.RvcOperationalState
Expand All @@ -54,12 +53,8 @@ def TC_RVCOPSTATE_2_1(self) -> list[str]:

@async_test_body
async def test_TC_RVCOPSTATE_2_1(self):

asserts.assert_true('PIXIT_ENDPOINT' in self.matter_test_config.global_test_params,
"PIXIT_ENDPOINT must be included on the command line in "
"the --int-arg flag as PIXIT_ENDPOINT:<endpoint>")

self.endpoint = self.matter_test_config.global_test_params['PIXIT_ENDPOINT']
self.endpoint = self.matter_test_config.endpoint
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")

attributes = Clusters.RvcOperationalState.Attributes

Expand Down Expand Up @@ -108,8 +103,7 @@ async def test_TC_RVCOPSTATE_2_1(self):

defined_states = [state.value for state in Clusters.OperationalState.Enums.OperationalStateEnum
if state is not Clusters.OperationalState.Enums.OperationalStateEnum.kUnknownEnumValue]
defined_states.extend(state.value for state in Clusters.RvcOperationalState.Enums.OperationalStateEnum
if state is not Clusters.RvcOperationalState.Enums.OperationalStateEnum.kUnknownEnumValue)
defined_states.extend(state.value for state in Clusters.RvcOperationalState.Enums.OperationalStateEnum)

for state in operational_state_list:
in_range = (0x80 <= state.operationalStateID <= 0xBF)
Expand Down Expand Up @@ -172,8 +166,7 @@ async def test_TC_RVCOPSTATE_2_1(self):
# Defined Errors
defined_errors = [error.value for error in Clusters.OperationalState.Enums.ErrorStateEnum
if error is not Clusters.OperationalState.Enums.ErrorStateEnum.kUnknownEnumValue]
defined_errors.extend(error.value for error in Clusters.RvcOperationalState.Enums.ErrorStateEnum
if error is not Clusters.RvcOperationalState.Enums.ErrorStateEnum.kUnknownEnumValue)
defined_errors.extend(error.value for error in Clusters.RvcOperationalState.Enums.ErrorStateEnum)

in_range = (0x80 <= operational_error.errorStateID <= 0xBF)
asserts.assert_true(operational_error.errorStateID in defined_errors
Expand Down
37 changes: 15 additions & 22 deletions src/python_testing/TC_RVCOPSTATE_2_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches
from mobly import asserts

# This test requires several additional command line arguments
# run with
# --int-arg PIXIT_ENDPOINT:<endpoint>


# Takes an OpState or RvcOpState state enum and returns a string representation
def state_enum_to_text(state_enum):
Expand Down Expand Up @@ -82,20 +78,20 @@ def pics_TC_RVCOPSTATE_2_3(self) -> list[str]:
class TC_RVCOPSTATE_2_3(MatterBaseTest):

def __init__(self, *args):
super().__init__(args)
self.endpoint = 0
super().__init__(*args)
self.endpoint = None

async def read_mod_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.RvcOperationalState
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)

async def send_pause_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.Pause:
async def send_pause_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse:
ret = await self.send_single_cmd(cmd=Clusters.Objects.RvcOperationalState.Commands.Pause(), endpoint=self.endpoint)
asserts.assert_true(type_matches(ret, Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse),
"Unexpected return type for Pause")
return ret

async def send_resume_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.Resume:
async def send_resume_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse:
ret = await self.send_single_cmd(cmd=Clusters.Objects.RvcOperationalState.Commands.Resume(), endpoint=self.endpoint)
asserts.assert_true(type_matches(ret, Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse),
"Unexpected return type for Resume")
Expand All @@ -108,23 +104,23 @@ async def read_operational_state_with_check(self, step_number, expected_state):
endpoint=self.endpoint, attribute=Clusters.RvcOperationalState.Attributes.OperationalState)
logging.info("OperationalState: %s" % operational_state)
asserts.assert_equal(operational_state, expected_state,
"OperationalState(%s) should be %s" % operational_state, state_enum_to_text(expected_state))
"OperationalState(%s) should be %s" % (operational_state, state_enum_to_text(expected_state)))

# Sends the Pause command and checks that the returned error matches the expected_error
async def send_pause_cmd_with_check(self, step_number, expected_error):
self.print_step(step_number, "Send Pause command")
ret = self.send_pause_cmd()
ret = await self.send_pause_cmd()
asserts.assert_equal(ret.commandResponseState.errorStateID, expected_error,
"errorStateID(%s) should be %s" % ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error))
"errorStateID(%s) should be %s" % (ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error)))

# Sends the Resume command and checks that the returned error matches the expected_error
async def send_resume_cmd_with_check(self, step_number, expected_error):
self.print_step(step_number, "Send Pause command")
ret = self.send_resume_cmd()
ret = await self.send_resume_cmd()
asserts.assert_equal(ret.commandResponseState.errorStateID, expected_error,
"errorStateID(%s) should be %s" % ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error))
"errorStateID(%s) should be %s" % (ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error)))

# Prints the instruction and waits for a user input to continue
def print_instruction(self, step_number, instruction):
Expand All @@ -134,18 +130,15 @@ def print_instruction(self, step_number, instruction):
@async_test_body
async def test_TC_RVCOPSTATE_2_3(self):

asserts.assert_true('PIXIT_ENDPOINT' in self.matter_test_config.global_test_params,
"PIXIT_ENDPOINT must be included on the command line in "
"the --int-arg flag as PIXIT_ENDPOINT:<endpoint>")

self.endpoint = self.matter_test_config.global_test_params['PIXIT_ENDPOINT']
self.endpoint = self.matter_test_config.endpoint
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")

asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0003"), "RVCOPSTATE.S.A0003 must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0004"), "RVCOPSTATE.S.A0004 must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C00.Rsp"), "RVCOPSTATE.S.C00.Rsp must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C03.Rsp"), "RVCOPSTATE.S.C03.Rsp must be supported")
# This command SHALL be supported by an implementation if any of the other commands are supported (6.5)
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C04.Rsp"), "RVCOPSTATE.S.C04.Rsp must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C04.Tx"), "RVCOPSTATE.S.C04.Tx must be supported")

attributes = Clusters.RvcOperationalState.Attributes
op_states = Clusters.OperationalState.Enums.OperationalStateEnum
Expand Down Expand Up @@ -208,7 +201,7 @@ async def test_TC_RVCOPSTATE_2_3(self):
attribute=attributes.OperationalState)
logging.info("OperationalState: %s" % operational_state)
asserts.assert_equal(operational_state, old_opstate_dut,
"OperationalState(%s) should be the state before pause (%s)" % operational_state, old_opstate_dut)
"OperationalState(%s) should be the state before pause (%s)" % (operational_state, old_opstate_dut))

await self.send_resume_cmd_with_check(13, op_errors.kNoError)

Expand Down
26 changes: 10 additions & 16 deletions src/python_testing/TC_RVCOPSTATE_2_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches
from mobly import asserts

# This test requires several additional command line arguments
# run with
# --int-arg PIXIT_ENDPOINT:<endpoint>


# Takes an OpState or RvcOpState state enum and returns a string representation
def state_enum_to_text(state_enum):
Expand Down Expand Up @@ -79,14 +75,14 @@ def pics_TC_RVCOPSTATE_2_4(self) -> list[str]:

class TC_RVCOPSTATE_2_4(MatterBaseTest):
def __init__(self, *args):
super().__init__(args)
self.endpoint = self.matter_test_config.global_test_params['PIXIT_ENDPOINT']
super().__init__(*args)
self.endpoint = None

async def read_mod_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.RvcOperationalState
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)

async def send_go_home_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.GoHome:
async def send_go_home_cmd(self) -> Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse:
ret = await self.send_single_cmd(cmd=Clusters.Objects.RvcOperationalState.Commands.GoHome(), endpoint=self.endpoint)
asserts.assert_true(type_matches(ret, Clusters.Objects.RvcOperationalState.Commands.OperationalCommandResponse),
"Unexpected return type for GoHome")
Expand All @@ -95,10 +91,10 @@ async def send_go_home_cmd(self) -> Clusters.Objects.RvcOperationalState.Command
# Sends the GoHome command and checks that the returned error matches the expected_error
async def send_go_home_cmd_with_check(self, step_number, expected_error):
self.print_step(step_number, "Send GoHome command")
ret = self.send_go_home_cmd()
ret = await self.send_go_home_cmd()
asserts.assert_equal(ret.commandResponseState.errorStateID, expected_error,
"errorStateID(%s) should be %s" % ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error))
"errorStateID(%s) should be %s" % (ret.commandResponseState.errorStateID,
error_enum_to_text(expected_error)))

# Prints the step number, reads the operational state attribute and checks if it matches with expected_state
async def read_operational_state_with_check(self, step_number, expected_state):
Expand All @@ -107,7 +103,7 @@ async def read_operational_state_with_check(self, step_number, expected_state):
endpoint=self.endpoint, attribute=Clusters.RvcOperationalState.Attributes.OperationalState)
logging.info("OperationalState: %s" % operational_state)
asserts.assert_equal(operational_state, expected_state,
"OperationalState(%s) should be %s" % operational_state, state_enum_to_text(expected_state))
"OperationalState(%s) should be %s" % (operational_state, state_enum_to_text(expected_state)))

# Prints the instruction and waits for a user input to continue
def print_instruction(self, step_number, instruction):
Expand All @@ -116,13 +112,11 @@ def print_instruction(self, step_number, instruction):

@async_test_body
async def test_TC_RVCOPSTATE_2_4(self):

asserts.assert_true('PIXIT_ENDPOINT' in self.matter_test_config.global_test_params,
"PIXIT_ENDPOINT must be included on the command line in "
"the --int-arg flag as PIXIT_ENDPOINT:<endpoint>")
self.endpoint = self.matter_test_config.endpoint
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")

asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0004"), "RVCOPSTATE.S.A0004 must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C04.Rsp"), "RVCOPSTATE.S.C04.Rsp must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C04.Tx"), "RVCOPSTATE.S.C04.Tx must be supported")
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C128.Rsp"), "RVCOPSTATE.S.C128.Rsp must be supported")

op_states = Clusters.OperationalState.Enums.OperationalStateEnum
Expand Down

0 comments on commit 0bd5786

Please sign in to comment.