examples/daemon: cherrypick traits fix
BUG: 27276010
Change-Id: I1c87df45681331eaf35c618cb72a975f273b44e8
daemon: register device after component init
7f2a5dcefb7e5d9785efeb4c68542fd3b2e4865f
daemon/light: fix light trait def
9e9023e1855760dd7545086f4204631ddf38703b
examples/speaker: fix volume trait
f7bfb6af844f3df9ef04ea8ddf8061763a21a837
examples/lock: fix lock trait
c96ee4e4e61dc308f685757b6fd5adcec3dd1614
Change-Id: I06d468faab07863f9af1eb81cf68a82707857fa4
Reviewed-on: https://weave-review.googlesource.com/2850
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/examples/daemon/common/daemon.h b/examples/daemon/common/daemon.h
index 0b3c25a..22591a2 100644
--- a/examples/daemon/common/daemon.h
+++ b/examples/daemon/common/daemon.h
@@ -92,16 +92,18 @@
http_client_.get(), network_.get(),
dns_sd_.get(), http_server_.get(),
wifi_.get(), bluetooth_.get());
-
if (!opts.registration_ticket.empty()) {
- weave::RegistrationData data;
- data.ticket_id = opts.registration_ticket;
- data.service_url = opts.service_url;
- device_->Register(data, base::Bind(&OnRegisterDeviceDone, device_.get()));
+ registration_data_.ticket_id = opts.registration_ticket;
+ registration_data_.service_url = opts.service_url;
}
}
- void Run() { task_runner_->Run(); }
+ void Run() {
+ if (!registration_data_.ticket_id.empty()) {
+ device_->Register(registration_data_, base::Bind(&OnRegisterDeviceDone, device_.get()));
+ }
+ task_runner_->Run();
+ }
weave::Device* GetDevice() const { return device_.get(); }
@@ -127,4 +129,5 @@
std::unique_ptr<weave::examples::HttpServerImpl> http_server_;
std::unique_ptr<weave::examples::WifiImpl> wifi_;
std::unique_ptr<weave::Device> device_;
+ weave::RegistrationData registration_data_;
};
diff --git a/examples/daemon/light/light.cc b/examples/daemon/light/light.cc
index 4cbf9b4..07c0231 100644
--- a/examples/daemon/light/light.cc
+++ b/examples/daemon/light/light.cc
@@ -19,7 +19,7 @@
"parameters": {
"state": {
"type": "string",
- "enum": [ "on", "standby" ]
+ "enum": [ "on", "off" ]
}
}
}
@@ -27,7 +27,7 @@
"state": {
"state": {
"type": "string",
- "enum": [ "on", "standby" ],
+ "enum": [ "on", "off" ],
"isRequired": true
}
}
@@ -38,23 +38,23 @@
"minimalRole": "user",
"parameters": {
"brightness": {
- "type": "integer",
- "minimum": 0,
- "maximum": 100
+ "type": "number",
+ "minimum": 0.0,
+ "maximum": 1.0
}
}
}
},
"state": {
"brightness": {
- "type": "integer",
+ "type": "number",
"isRequired": true,
- "minimum": 0,
- "maximum": 100
+ "minimum": 0.0,
+ "maximum": 1.0
}
}
},
- "colorXY": {
+ "colorXy": {
"commands": {
"setConfig": {
"minimalRole": "user",
@@ -157,7 +157,7 @@
})";
const char kDefaultState[] = R"({
- "colorXY": {
+ "colorXy": {
"colorSetting": {"colorX": 0, "colorY": 0},
"colorCapRed": {"colorX": 0.674, "colorY": 0.322},
"colorCapGreen":{"colorX": 0.408, "colorY": 0.517},
@@ -178,7 +178,7 @@
device_ = device;
device->AddTraitDefinitionsFromJson(kTraits);
- CHECK(device->AddComponent(kComponent, {"onOff", "brightness", "colorXY"},
+ CHECK(device->AddComponent(kComponent, {"onOff", "brightness", "colorXy"},
nullptr));
CHECK(
device->SetStatePropertiesFromJson(kComponent, kDefaultState, nullptr));
@@ -190,7 +190,7 @@
device->AddCommandHandler(kComponent, "brightness.setConfig",
base::Bind(&LightHandler::OnBrightnessSetConfig,
weak_ptr_factory_.GetWeakPtr()));
- device->AddCommandHandler(kComponent, "colorXY.setConfig",
+ device->AddCommandHandler(kComponent, "colorXy.setConfig",
base::Bind(&LightHandler::OnColorXYSetConfig,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -252,17 +252,17 @@
return;
LOG(INFO) << "received command: " << cmd->GetName();
const auto& params = cmd->GetParameters();
- const base::DictionaryValue* colorXY = nullptr;
- if (params.GetDictionary("colorSetting", &colorXY)) {
+ const base::DictionaryValue* colorXy = nullptr;
+ if (params.GetDictionary("colorSetting", &colorXy)) {
bool updateState = false;
double X = 0.0;
double Y = 0.0;
- if (colorXY->GetDouble("colorX", &X)) {
+ if (colorXy->GetDouble("colorX", &X)) {
color_X_ = X;
updateState = true;
}
- if (colorXY->GetDouble("colorY", &Y)) {
+ if (colorXy->GetDouble("colorY", &Y)) {
color_Y_ = Y;
updateState = true;
}
@@ -282,13 +282,13 @@
void UpdateLightState() {
base::DictionaryValue state;
- state.SetString("onOff.state", light_status_ ? "on" : "standby");
+ state.SetString("onOff.state", light_status_ ? "on" : "off");
state.SetInteger("brightness.brightness", brightness_state_);
- std::unique_ptr<base::DictionaryValue> colorXY(new base::DictionaryValue());
- colorXY->SetDouble("colorX", color_X_);
- colorXY->SetDouble("colorY", color_Y_);
- state.Set("colorXY.colorSetting", colorXY.release());
+ std::unique_ptr<base::DictionaryValue> colorXy(new base::DictionaryValue());
+ colorXy->SetDouble("colorX", color_X_);
+ colorXy->SetDouble("colorY", color_Y_);
+ state.Set("colorXy.colorSetting", colorXy.release());
device_->SetStateProperties(kComponent, state, nullptr);
}
diff --git a/examples/daemon/lock/lock.cc b/examples/daemon/lock/lock.cc
index a2da9cf..32ce12d 100644
--- a/examples/daemon/lock/lock.cc
+++ b/examples/daemon/lock/lock.cc
@@ -38,7 +38,7 @@
"enum": [ "locked", "unlocked" ]
}
},
- "errors": ["batteryTooLow", "jammed", "lockingNotSupported"]
+ "errors": [ "jammed", "lockingNotSupported" ]
}
},
"state": {
diff --git a/examples/daemon/speaker/speaker.cc b/examples/daemon/speaker/speaker.cc
index 35eee2f..56da840 100644
--- a/examples/daemon/speaker/speaker.cc
+++ b/examples/daemon/speaker/speaker.cc
@@ -19,7 +19,7 @@
"parameters": {
"state": {
"type": "string",
- "enum": [ "on", "standby" ]
+ "enum": [ "on", "off" ]
}
}
}
@@ -27,7 +27,7 @@
"state": {
"state": {
"type": "string",
- "enum": [ "on", "standby" ],
+ "enum": [ "on", "off" ],
"isRequired": true
}
}
@@ -149,7 +149,7 @@
void UpdateSpeakerState() {
base::DictionaryValue state;
- state.SetString("onOff.state", speaker_status_ ? "on" : "standby");
+ state.SetString("onOff.state", speaker_status_ ? "on" : "off");
state.SetBoolean("volume.isMuted", isMuted_status_);
state.SetInteger("volume.volume", volume_value_);
device_->SetStateProperties(kComponent, state, nullptr);