maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.1k stars 169 forks source link

Negative values in characteristic "CurrentTemperature" #86

Closed GermanSheepDog closed 5 years ago

GermanSheepDog commented 5 years ago

Hello, I have been working on a temperature sensors for a freezer and I found that negative temperatures did not appear on my homekit device.

The reason is this description in "HAP-Specification-Non-Commercial-Version.pdf":

8.9 Current Temperature
...
UUID | 00000011-0000-1000-8000-0026BB765291
...
Minimum Value | 0

This was correctly implemented in /homekit/characteristics.h:

#define HOMEKIT_CHARACTERISTIC_CURRENT_TEMPERATURE HOMEKIT_APPLE_UUID2("11")
#define HOMEKIT_DECLARE_CHARACTERISTIC_CURRENT_TEMPERATURE(_value, ...) \
    .type = HOMEKIT_CHARACTERISTIC_CURRENT_TEMPERATURE, \
    .description = "Current Temperature", \
  ...  
  .min_value = (float[]) {0}, \  

It is necessary to change this:

#define HOMEKIT_CHARACTERISTIC_CURRENT_TEMPERATURE HOMEKIT_APPLE_UUID2("11")
#define HOMEKIT_DECLARE_CHARACTERISTIC_CURRENT_TEMPERATURE(_value, ...) \
    .type = HOMEKIT_CHARACTERISTIC_CURRENT_TEMPERATURE, \
    .description = "Current Temperature", \
  ...  
  .min_value = (float[]) {-100}, \  

After the change everything worked fine.

maximkulkin commented 5 years ago

These characteristics are defined as they are defined in Apple HAP specification. But anyways, you should be able to customize it on the spot, without having to change eps-homekit code:

HOMEKIT_CHARACTERISTIC(CURRENT_TEMPERATURE, 22, .min_value=(float[]) {-100}),