libweave: Cleanup enum to string conversion

Conversion should be done using weave::EnumToString
and weave::StringToEnum.
enum_to_string header moved public interface.

BUG=brillo:1242
TEST='FEATURES=test emerge-gizmo buffet'

Change-Id: I96af61ef0b263d4ec149b14a7c9055bd51bf2e4c
Reviewed-on: https://chromium-review.googlesource.com/285775
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Trybot-Ready: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/libweave/src/commands/command_dictionary.cc b/libweave/src/commands/command_dictionary.cc
index 5ad1939..536c7fc 100644
--- a/libweave/src/commands/command_dictionary.cc
+++ b/libweave/src/commands/command_dictionary.cc
@@ -9,6 +9,7 @@
 
 #include "libweave/src/commands/command_definition.h"
 #include "libweave/src/commands/schema_constants.h"
+#include "weave/enum_to_string.h"
 
 namespace weave {
 
@@ -131,7 +132,11 @@
 
       if (command_def_json->GetString(commands::attributes::kCommand_Role,
                                       &value)) {
-        if (!FromString(value, &minimal_role, error)) {
+        if (!StringToEnum(value, &minimal_role)) {
+          chromeos::Error::AddToPrintf(error, FROM_HERE,
+                                       errors::commands::kDomain,
+                                       errors::commands::kInvalidPropValue,
+                                       "Invalid role: '%s'", value.c_str());
           chromeos::Error::AddToPrintf(
               error, FROM_HERE, errors::commands::kDomain,
               errors::commands::kInvalidMinimalRole,
@@ -236,7 +241,7 @@
     command_def->Set(commands::attributes::kCommand_Parameters,
                      parameters.release());
     command_def->SetString(commands::attributes::kCommand_Role,
-                           ToString(pair.second->GetMinimalRole()));
+                           EnumToString(pair.second->GetMinimalRole()));
     package->SetWithoutPathExpansion(command_name, command_def);
   }
   return dict;