コード例 #1
0
/*
 * MyNode::removeValue
 * Per notification, remove value from node.
 */
void MyNode::removeValue (ValueID id)
{
	vector<MyValue*>::iterator it;
	bool found = false;
	for (it = values.begin(); it != values.end(); it++) {
		if ((*it)->id == id) {
			delete *it;
			values.erase(it);
			found = true;
			break;
		}
	}
	if (!found)
		fprintf(stderr, "removeValue not found Home 0x%08x Node %d Genre %s Class %s Instance %d Index %d Type %s\n",
				id.GetHomeId(), id.GetNodeId(), valueGenreStr(id.GetGenre()),
				cclassStr(id.GetCommandClassId()), id.GetInstance(), id.GetIndex(),
				valueTypeStr(id.GetType()));

	setTime(time(NULL));
	setChanged(true);
}
コード例 #2
0
json_spirit::Object ZWaveController::GetValueInfo(ValueID v){

	int home_id = (int)v.GetHomeId();
	int node_id = (int)v.GetNodeId();

	string product_name = Manager::Get()->GetNodeProductName(home_id, node_id);
	string product_id = Manager::Get()->GetNodeProductId(home_id, node_id);
	string product_type = Manager::Get()->GetNodeProductType(home_id, node_id);
	string node_type = Manager::Get()->GetNodeType(home_id, node_id);

	json_spirit::Object prop_info;

	prop_info.push_back(json_spirit::Pair("node_id", node_id));

	prop_info.push_back(json_spirit::Pair("node_type", node_type));

	prop_info.push_back(json_spirit::Pair("product_name", product_name));

	prop_info.push_back(json_spirit::Pair("product_id", product_id));

	prop_info.push_back(json_spirit::Pair("product_type", product_type));
	
	uint64 vid = v.GetId();
	string s_vid = boost::lexical_cast<string>(vid);
	prop_info.push_back(json_spirit::Pair("value_id", s_vid));

	prop_info.push_back(json_spirit::Pair("label", Manager::Get()->GetValueLabel(v)));

	prop_info.push_back(json_spirit::Pair("help_text", Manager::Get()->GetValueHelp(v)));

	bool bool_prop_value;
	uint8 int8_prop_value;
	int32 int32_prop_value;
	string s_int32_prop_value;
	int16 int16_prop_value;
	string str_prop_value;

	switch (v.GetType()){
	case ValueID::ValueType::ValueType_Bool:
		prop_info.push_back(json_spirit::Pair("type", "bool"));
		prop_info.push_back(json_spirit::Pair("type_help", "0/1, true/false, on/off"));
		Manager::Get()->GetValueAsBool(v, &bool_prop_value);
		prop_info.push_back(json_spirit::Pair("value", bool_prop_value));
		break;
	case ValueID::ValueType::ValueType_Byte:
		prop_info.push_back(json_spirit::Pair("type", "byte"));
		prop_info.push_back(json_spirit::Pair("type_help", "number from 0 to 255"));
		Manager::Get()->GetValueAsByte(v, &int8_prop_value);
		prop_info.push_back(json_spirit::Pair("value", int8_prop_value));
		break;
	case ValueID::ValueType::ValueType_Short:
		prop_info.push_back(json_spirit::Pair("type", "short"));
		prop_info.push_back(json_spirit::Pair("type_help", "number from 0 to 65,535"));
		Manager::Get()->GetValueAsShort(v, &int16_prop_value);
		prop_info.push_back(json_spirit::Pair("value", int16_prop_value));
		break;
	case ValueID::ValueType::ValueType_Decimal:
	case ValueID::ValueType::ValueType_Int:
		prop_info.push_back(json_spirit::Pair("type", "int32"));
		prop_info.push_back(json_spirit::Pair("type_help", "number from 0 to 4,294,967,295"));
		Manager::Get()->GetValueAsInt(v, &int32_prop_value);

		// do all this checking below because of a bug in openzwave: https://code.google.com/p/open-zwave/issues/detail?id=382
		s_int32_prop_value = boost::lexical_cast<string>(int32_prop_value);
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		if (boost::iequals(s_int32_prop_value, str_prop_value)){
			// bug did not happen
			prop_info.push_back(json_spirit::Pair("value", int32_prop_value));
		}
		else {
			// bug DID happen
			prop_info.push_back(json_spirit::Pair("value", str_prop_value));
		}
		break;
	case ValueID::ValueType::ValueType_List:
	{
		prop_info.push_back(json_spirit::Pair("type", "list"));
		prop_info.push_back(json_spirit::Pair("type_help", "list"));
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		prop_info.push_back(json_spirit::Pair("value", str_prop_value));

		std::vector<string> list_options;
		Manager::Get()->GetValueListItems(v, &list_options);
		std::vector<json_spirit::Value> values;
		for (std::vector<string>::iterator i = list_options.begin(); i != list_options.end(); ++i){
			string opt = *i;
			values.push_back(opt);
		}
		prop_info.push_back(json_spirit::Pair("list_options", values));

		break;
	}
	case ValueID::ValueType::ValueType_Schedule:
		prop_info.push_back(json_spirit::Pair("type", "schedule"));
		prop_info.push_back(json_spirit::Pair("type_help", "schedule"));
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		prop_info.push_back(json_spirit::Pair("value", str_prop_value));
		break;
	case ValueID::ValueType::ValueType_String:
		prop_info.push_back(json_spirit::Pair("type", "string"));
		prop_info.push_back(json_spirit::Pair("type_help", "string"));
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		prop_info.push_back(json_spirit::Pair("value", str_prop_value));
		break;
	case ValueID::ValueType::ValueType_Button:
		prop_info.push_back(json_spirit::Pair("type", "button"));
		prop_info.push_back(json_spirit::Pair("type_help", "button (string)"));
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		prop_info.push_back(json_spirit::Pair("value", str_prop_value));
		break;
	case ValueID::ValueType::ValueType_Raw:
		prop_info.push_back(json_spirit::Pair("type", "raw"));
		prop_info.push_back(json_spirit::Pair("type_help", "raw (string)"));
		Manager::Get()->GetValueAsString(v, &str_prop_value);
		prop_info.push_back(json_spirit::Pair("value", str_prop_value));
		break;
	default:
		prop_info.push_back(json_spirit::Pair("type", "unknown"));
		prop_info.push_back(json_spirit::Pair("type_help", "unknown"));
		prop_info.push_back(json_spirit::Pair("value", ""));
		break;
	}

	Manager::Get()->GetValueAsString(v, &str_prop_value);
	prop_info.push_back(json_spirit::Pair("string value", str_prop_value));

	prop_info.push_back(json_spirit::Pair("max", Manager::Get()->GetValueMax(v)));

	prop_info.push_back(json_spirit::Pair("min", Manager::Get()->GetValueMin(v)));

	prop_info.push_back(json_spirit::Pair("units", Manager::Get()->GetValueUnits(v)));

	prop_info.push_back(json_spirit::Pair("is_polled", Manager::Get()->IsValuePolled(v)));

	prop_info.push_back(json_spirit::Pair("read_only", Manager::Get()->IsValueReadOnly(v)));

	prop_info.push_back(json_spirit::Pair("write_only", Manager::Get()->IsValueWriteOnly(v)));

	prop_info.push_back(json_spirit::Pair("has_been_set", Manager::Get()->IsValueSet(v)));

	switch (v.GetGenre()){
	case ValueID::ValueGenre::ValueGenre_Basic:
		prop_info.push_back(json_spirit::Pair("genre", "basic"));
		break;
	case ValueID::ValueGenre::ValueGenre_User:
		prop_info.push_back(json_spirit::Pair("genre", "user"));
		break;
	case ValueID::ValueGenre::ValueGenre_Config:
		prop_info.push_back(json_spirit::Pair("genre", "config"));
		break;
	case ValueID::ValueGenre::ValueGenre_System:
		prop_info.push_back(json_spirit::Pair("genre", "system"));
		break;
	case ValueID::ValueGenre::ValueGenre_Count:
		prop_info.push_back(json_spirit::Pair("genre", "count"));
		break;
	default:
		prop_info.push_back(json_spirit::Pair("genre", "unknown"));
		break;
	}

	return prop_info;

}