Yurik72/ESPHap

Setting initial values for FLOAT type

Closed this issue · 2 comments

Hello,

I can't seem to find a related function for setting initial values for FLOAT numbers.
After taking a look inside the homeintegration.c and homeintegration.h, I just can find those for BOOL, UINT8, UINT16, UINT32 and INT.

  • homeintegration.h
	//initial value
#define INIT_CHARACHTERISTIC_VAL(type,ch,val) \
		hap_set_initial_characteristic_##type##_value(ch,val);
#define INIT_CHARACHTERISTIC_VAL_BY_TYPE(type,service,ch,val) \
		hap_setinitial_characteristic_##type##_value(service,ch,val);

	void hap_setinitial_characteristic_int_value(homekit_service_t* s, const char *type, int val);
	void hap_setinitial_characteristic_bool_value(homekit_service_t* s, const char *type, bool val);

	void hap_set_initial_characteristic_int_value(homekit_characteristic_t* ch, int val);
	void hap_set_initial_characteristic_bool_value(homekit_characteristic_t* ch, bool bval);
  • homeintegration.c
void hap_setinitial_characteristic_int_value(homekit_service_t* s, const char *type,int val ) {
	hap_set_initial_characteristic_int_value(homekit_service_characteristic_by_type(s, type), val);
}
void hap_setinitial_characteristic_bool_value(homekit_service_t* s, const char *type, bool val) {
	hap_set_initial_characteristic_int_value(homekit_service_characteristic_by_type(s, type), val);
}

void hap_set_initial_characteristic_int_value(homekit_characteristic_t* ch, int val) {
	if (!ch
		||
		(ch->format != homekit_format_uint8 && ch->format != homekit_format_uint16
			&& ch->format != homekit_format_uint32 && ch->format != homekit_format_int)
		)
	{
		ERROR("Wrong default value\n");
		return;
	}
	ch->value.int_value = hap_constrain(val, *ch->min_value, *ch->max_value);
	if (ch->value.int_value != val) {
		ERROR("Default value is out of range, Set %d instead", ch->value.int_value);
	}
}
void hap_set_initial_characteristic_bool_value(homekit_characteristic_t* ch, bool bval) {
	if (!ch	||	(ch->format != homekit_format_bool))
	{
		ERROR("Wrong default value\n");
		return;
	}
	ch->value.bool_value = bval;

}

When trying to compile with this line, I get a compilation error with these informations

  • INIT_CHARACHTERISTIC_VAL_BY_TYPE(float, SERVICE, CHARACTERISTIC, FLOAT VALUE);
homeintegration.h:215:3: error: 'hap_setinitial_characteristic_float_value' was not declared in this scope
   hap_setinitial_characteristic_##type##_value(service,ch,val);
homeintegration.h:215:3: note: in definition of macro 'INIT_CHARACHTERISTIC_VAL_BY_TYPE'
   hap_setinitial_characteristic_##type##_value(service,ch,val);

Any chance to get this added in the next version ?

Well, it seems like this REPO is not updated anymore // at least I get no answer on my issues.

So I managed to get this sorted out.
For those having the same problem, add these lines (commented by "// SIMKARD") in each file :

  • homeintegration.h
	void hap_setinitial_characteristic_float_value(homekit_service_t* s, const char *type, float val);			// SIMKARD
	void hap_setinitial_characteristic_int_value(homekit_service_t* s, const char *type, int val);
	void hap_setinitial_characteristic_bool_value(homekit_service_t* s, const char *type, bool val);

	void hap_set_initial_characteristic_float_value(homekit_characteristic_t* ch, float val);						// SIMKARD
	void hap_set_initial_characteristic_int_value(homekit_characteristic_t* ch, int val);
	void hap_set_initial_characteristic_bool_value(homekit_characteristic_t* ch, bool bval);
  • homeintegration.c
void hap_setinitial_characteristic_float_value(homekit_service_t* s, const char *type,float val ) {				// SIMKARD
	hap_set_initial_characteristic_float_value(homekit_service_characteristic_by_type(s, type), val);
}
void hap_setinitial_characteristic_int_value(homekit_service_t* s, const char *type,int val ) {
	hap_set_initial_characteristic_int_value(homekit_service_characteristic_by_type(s, type), val);
}
void hap_setinitial_characteristic_bool_value(homekit_service_t* s, const char *type, bool val) {
	hap_set_initial_characteristic_int_value(homekit_service_characteristic_by_type(s, type), val);
}

void hap_set_initial_characteristic_float_value(homekit_characteristic_t* ch, float val) {						// SIMKARD
	if (!ch
		||
		(ch->format != homekit_format_float)
		)
	{
		ERROR("Wrong default value\n");
		return;
	}
	ch->value.float_value = hap_constrain(val, *ch->min_value, *ch->max_value);
	if (ch->value.float_value != val) {
		ERROR("Default value is out of range, Set %d instead", ch->value.float_value);
	}
}
void hap_set_initial_characteristic_int_value(homekit_characteristic_t* ch, int val) {
	if (!ch
		||
		(ch->format != homekit_format_uint8 && ch->format != homekit_format_uint16
			&& ch->format != homekit_format_uint32 && ch->format != homekit_format_int)
		)
	{
		ERROR("Wrong default value\n");
		return;
	}
	ch->value.int_value = hap_constrain(val, *ch->min_value, *ch->max_value);
	if (ch->value.int_value != val) {
		ERROR("Default value is out of range, Set %d instead", ch->value.int_value);
	}
}
void hap_set_initial_characteristic_bool_value(homekit_characteristic_t* ch, bool bval) {
	if (!ch	||	(ch->format != homekit_format_bool))
	{
		ERROR("Wrong default value\n");
		return;
	}
	ch->value.bool_value = bval;

}

Managed to get it working by using these lines after initialization of all accessories and services :

hap_set_charachteristic_validrange_by_type(HomeKit_Service, HOMEKIT_CHARACTERISTIC_HEATING_THRESHOLD_TEMPERATURE, 16.0, 31.0);