Fix new schema to match the new server definitions
A new server version now validates the state definitions in
traits as well as commands and some of our sample traits were
not defined properly. Also, the server now requires the 'base'
trait to be complete (and have base.reboot and base.identify
commands defined).
Change-Id: Icc576918895eba642498aa9b8bb1771825562f06
Reviewed-on: https://weave-review.googlesource.com/1971
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/base_api_handler.cc b/src/base_api_handler.cc
index 9c64463..5562b6c 100644
--- a/src/base_api_handler.cc
+++ b/src/base_api_handler.cc
@@ -13,7 +13,7 @@
namespace weave {
namespace {
-const char kBaseComponent[] = "weave";
+const char kBaseComponent[] = "base";
const char kBaseTrait[] = "base";
const char kBaseStateFirmwareVersion[] = "base.firmwareVersion";
const char kBaseStateAnonymousAccessRole[] = "base.localAnonymousAccessMaxRole";
@@ -55,13 +55,45 @@
"type": "string"
}
}
+ },
+ "reboot": {
+ "minimalRole": "user",
+ "parameters": {},
+ "errors": ["notEnoughBattery"]
+ },
+ "identify": {
+ "minimalRole": "user",
+ "parameters": {}
}
},
"state": {
- "firmwareVersion": "string",
- "localDiscoveryEnabled": "boolean",
- "localAnonymousAccessMaxRole": [ "none", "viewer", "user" ],
- "localPairingEnabled": "boolean"
+ "firmwareVersion": {
+ "type": "string",
+ "isRequired": true
+ },
+ "localDiscoveryEnabled": {
+ "type": "boolean",
+ "isRequired": true
+ },
+ "localAnonymousAccessMaxRole": {
+ "type": "string",
+ "enum": [ "none", "viewer", "user" ],
+ "isRequired": true
+ },
+ "localPairingEnabled": {
+ "type": "boolean",
+ "isRequired": true
+ },
+ "connectionStatus": {
+ "type": "string"
+ },
+ "network": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "name": { "type": "string" }
+ }
+ }
}
}
})");
diff --git a/src/base_api_handler_unittest.cc b/src/base_api_handler_unittest.cc
index e0ebf88..6f8460b 100644
--- a/src/base_api_handler_unittest.cc
+++ b/src/base_api_handler_unittest.cc
@@ -133,14 +133,46 @@
"type": "string"
}
}
+ },
+ "reboot": {
+ "minimalRole": "user",
+ "parameters": {},
+ "errors": ["notEnoughBattery"]
+ },
+ "identify": {
+ "minimalRole": "user",
+ "parameters": {}
}
},
- "state": {
- "firmwareVersion": "string",
- "localAnonymousAccessMaxRole": [ "none", "viewer", "user" ],
- "localDiscoveryEnabled": "boolean",
- "localPairingEnabled": "boolean"
- }
+ "state": {
+ "firmwareVersion": {
+ "type": "string",
+ "isRequired": true
+ },
+ "localDiscoveryEnabled": {
+ "type": "boolean",
+ "isRequired": true
+ },
+ "localAnonymousAccessMaxRole": {
+ "type": "string",
+ "enum": [ "none", "viewer", "user" ],
+ "isRequired": true
+ },
+ "localPairingEnabled": {
+ "type": "boolean",
+ "isRequired": true
+ },
+ "connectionStatus": {
+ "type": "string"
+ },
+ "network": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "name": { "type": "string" }
+ }
+ }
+ }
})";
EXPECT_JSON_EQ(expected, *trait);
}
@@ -150,7 +182,7 @@
AddCommand(R"({
'name' : 'base.updateBaseConfiguration',
- 'component': 'weave',
+ 'component': 'base',
'parameters': {
'localDiscoveryEnabled': false,
'localAnonymousAccessMaxRole': 'none',
@@ -171,7 +203,7 @@
AddCommand(R"({
'name' : 'base.updateBaseConfiguration',
- 'component': 'weave',
+ 'component': 'base',
'parameters': {
'localDiscoveryEnabled': true,
'localAnonymousAccessMaxRole': 'user',
@@ -205,7 +237,7 @@
TEST_F(BaseApiHandlerTest, UpdateDeviceInfo) {
AddCommand(R"({
'name' : 'base.updateDeviceInfo',
- 'component': 'weave',
+ 'component': 'base',
'parameters': {
'name': 'testName',
'description': 'testDescription',
@@ -220,7 +252,7 @@
AddCommand(R"({
'name' : 'base.updateDeviceInfo',
- 'component': 'weave',
+ 'component': 'base',
'parameters': {
'location': 'newLocation'
}
diff --git a/src/device_registration_info.cc b/src/device_registration_info.cc
index 47fa40c..e70b8ba 100644
--- a/src/device_registration_info.cc
+++ b/src/device_registration_info.cc
@@ -512,9 +512,6 @@
channel->SetString("supportedType", "pull");
}
resource->Set("channel", channel.release());
- resource->Set("commandDefs",
- component_manager_->GetLegacyCommandDefinitions().DeepCopy());
- resource->Set("state", component_manager_->GetLegacyState().DeepCopy());
resource->Set("traits", component_manager_->GetTraits().DeepCopy());
resource->Set("components", component_manager_->GetComponents().DeepCopy());
diff --git a/src/device_registration_info_unittest.cc b/src/device_registration_info_unittest.cc
index 8be0c97..327c440 100644
--- a/src/device_registration_info_unittest.cc
+++ b/src/device_registration_info_unittest.cc
@@ -430,73 +430,41 @@
EXPECT_TRUE(json->GetString("deviceDraft.name", &value));
EXPECT_EQ("Coffee Pot", value);
base::DictionaryValue* dict = nullptr;
- EXPECT_TRUE(json->GetDictionary("deviceDraft.commandDefs", &dict));
- auto expectedCommandDefs = R"({
- 'base': {
- 'reboot': {
- 'parameters': {
- 'delay': {
- 'minimum': 10,
- 'type': 'integer'
- }
- },
- 'minimalRole': 'user'
- }
- },
- 'robot': {
- '_jump': {
- 'parameters': {
- '_height': {
- 'type': 'integer'
- }
- },
- 'minimalRole': 'user'
- }
- }
- })";
- EXPECT_JSON_EQ(expectedCommandDefs, *dict);
-
- EXPECT_TRUE(json->GetDictionary("deviceDraft.state", &dict));
- auto expectedState = R"({
- 'base': {
- 'firmwareVersion': '1.0'
- }
- })";
- EXPECT_JSON_EQ(expectedState, *dict);
-
+ EXPECT_FALSE(json->GetDictionary("deviceDraft.commandDefs", &dict));
+ EXPECT_FALSE(json->GetDictionary("deviceDraft.state", &dict));
EXPECT_TRUE(json->GetDictionary("deviceDraft.traits", &dict));
auto expectedTraits = R"({
- 'base': {
- 'commands': {
- 'reboot': {
- 'parameters': {'delay': {'minimum': 10, 'type': 'integer'}},
- 'minimalRole': 'user'
+ 'base': {
+ 'commands': {
+ 'reboot': {
+ 'parameters': {'delay': {'minimum': 10, 'type': 'integer'}},
+ 'minimalRole': 'user'
+ }
+ },
+ 'state': {
+ 'firmwareVersion': {'type': 'string'}
}
},
- 'state': {
- 'firmwareVersion': {'type': 'string'}
- }
- },
- 'robot': {
- 'commands': {
- '_jump': {
- 'parameters': {'_height': {'type': 'integer'}},
- 'minimalRole': 'user'
+ 'robot': {
+ 'commands': {
+ '_jump': {
+ 'parameters': {'_height': {'type': 'integer'}},
+ 'minimalRole': 'user'
+ }
}
}
- }
- })";
+ })";
EXPECT_JSON_EQ(expectedTraits, *dict);
EXPECT_TRUE(json->GetDictionary("deviceDraft.components", &dict));
auto expectedComponents = R"({
- 'comp': {
- 'traits': ['base', 'robot'],
- 'state': {
- 'base': { 'firmwareVersion': '1.0' }
+ 'comp': {
+ 'traits': ['base', 'robot'],
+ 'state': {
+ 'base': { 'firmwareVersion': '1.0' }
+ }
}
- }
- })";
+ })";
EXPECT_JSON_EQ(expectedComponents, *dict);
base::DictionaryValue json_resp;