Fix weaved to make it work with the new libweave

There have been some API changes on libweave side, so we must
update weaved to work with the new drop of the library.

Change-Id: Idf173557769b5b1c6fa6b73cfc75342301a89e99
diff --git a/buffet/dbus_command_proxy.cc b/buffet/dbus_command_proxy.cc
index d0eeb15..b7e82c1 100644
--- a/buffet/dbus_command_proxy.cc
+++ b/buffet/dbus_command_proxy.cc
@@ -64,12 +64,12 @@
   dbus_adaptor_.SetId(command->GetID());
   dbus_adaptor_.SetState(EnumToString(command->GetState()));
   dbus_adaptor_.SetProgress(
-      DictionaryToDBusVariantDictionary(*command->GetProgress()));
+      DictionaryToDBusVariantDictionary(command->GetProgress()));
   dbus_adaptor_.SetOrigin(EnumToString(command->GetOrigin()));
   dbus_adaptor_.SetParameters(
-      DictionaryToDBusVariantDictionary(*command->GetParameters()));
+      DictionaryToDBusVariantDictionary(command->GetParameters()));
   dbus_adaptor_.SetResults(
-      DictionaryToDBusVariantDictionary(*command->GetResults()));
+      DictionaryToDBusVariantDictionary(command->GetResults()));
 
   // Register the command DBus object and expose its methods and properties.
   dbus_object_.RegisterAsync(completion_callback);
@@ -93,7 +93,7 @@
     return false;
   }
   dbus_adaptor_.SetProgress(
-      DictionaryToDBusVariantDictionary(*command->GetProgress()));
+      DictionaryToDBusVariantDictionary(command->GetProgress()));
   dbus_adaptor_.SetState(EnumToString(command->GetState()));
   return true;
 }
@@ -115,7 +115,7 @@
     return false;
   }
   dbus_adaptor_.SetResults(
-      DictionaryToDBusVariantDictionary(*command->GetResults()));
+      DictionaryToDBusVariantDictionary(command->GetResults()));
   dbus_adaptor_.SetState(EnumToString(command->GetState()));
   return true;
 }
diff --git a/buffet/dbus_command_proxy_unittest.cc b/buffet/dbus_command_proxy_unittest.cc
index 410aa58..0aa701d 100644
--- a/buffet/dbus_command_proxy_unittest.cc
+++ b/buffet/dbus_command_proxy_unittest.cc
@@ -36,6 +36,7 @@
 using ::testing::_;
 using ::testing::AnyNumber;
 using ::testing::Return;
+using ::testing::ReturnRef;
 using ::testing::ReturnRefOfCopy;
 using ::testing::StrictMock;
 
@@ -71,6 +72,8 @@
     EXPECT_CALL(*bus_, AssertOnOriginThread()).Times(AnyNumber());
     EXPECT_CALL(*bus_, AssertOnDBusThread()).Times(AnyNumber());
 
+    expected_result_dict_.SetInteger("height", 53);
+    expected_result_dict_.SetString("_jumpType", "_withKick");
     EXPECT_CALL(*command_, GetID())
         .WillOnce(ReturnRefOfCopy<std::string>(kTestCommandId));
     // Use WillRepeatedly because GetName is used for logging.
@@ -80,15 +83,12 @@
         .WillRepeatedly(Return(weave::Command::State::kQueued));
     EXPECT_CALL(*command_, GetOrigin())
         .WillOnce(Return(weave::Command::Origin::kLocal));
-    EXPECT_CALL(*command_, MockGetParameters())
-        .WillOnce(ReturnRefOfCopy<std::string>(R"({
-          'height': 53,
-          '_jumpType': '_withKick'
-        })"));
-    EXPECT_CALL(*command_, MockGetProgress())
-        .WillRepeatedly(ReturnRefOfCopy<std::string>("{}"));
-    EXPECT_CALL(*command_, MockGetResults())
-        .WillRepeatedly(ReturnRefOfCopy<std::string>("{}"));
+    EXPECT_CALL(*command_, GetParameters())
+        .WillOnce(ReturnRef(expected_result_dict_));
+    EXPECT_CALL(*command_, GetProgress())
+        .WillRepeatedly(ReturnRef(empty_dict_));
+    EXPECT_CALL(*command_, GetResults())
+        .WillRepeatedly(ReturnRef(empty_dict_));
 
     // Set up a mock ExportedObject to be used with the DBus command proxy.
     std::string cmd_path = buffet::dbus_constants::kCommandServicePathPrefix;
@@ -133,6 +133,8 @@
 
   scoped_refptr<dbus::MockExportedObject> mock_exported_object_command_;
   scoped_refptr<dbus::MockBus> bus_;
+  base::DictionaryValue empty_dict_;
+  base::DictionaryValue expected_result_dict_;
 
   std::shared_ptr<StrictMock<weave::test::MockCommand>> command_;
   std::unique_ptr<DBusCommandProxy> proxy_;
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 00e6dc8..61a5d7a 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -284,10 +284,9 @@
 }
 
 bool Manager::GetState(brillo::ErrorPtr* error, std::string* state) {
-  auto json = device_->GetState();
-  CHECK(json);
+  const base::DictionaryValue& json = device_->GetState();
   base::JSONWriter::WriteWithOptions(
-      *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
+      json, base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
   return true;
 }
 
@@ -322,11 +321,10 @@
 }
 
 void Manager::OnStateChanged() {
-  auto state = device_->GetState();
-  CHECK(state);
+  const base::DictionaryValue& state = device_->GetState();
   std::string json;
   base::JSONWriter::WriteWithOptions(
-      *state, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
+      state, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
   dbus_adaptor_.SetState(json);
 }