AmendHub

Download:

cyberslak

/

lightsout

/

amendments

/

19

Work around HA brightness range quirks

Some lights in HA have a brightness range of 1-255, and some of 1-254 (notably Zigbee lights), without any way of distinguishing the two. To handle both, we internally use the 1-255 range (0 = off) and map 254 to 255 when requesting the entity state. This means we may show 99.6% brightness as 100%, but that is far better than showing it as 99% and being unable to set a light to 100%.

cyberslak made amendment 19 21 days ago
--- ha.c Sun Mar 9 23:03:13 2025 +++ ha.c Thu Mar 13 22:12:10 2025 @@ -49,6 +49,12 @@ short ha_get_entity_state(const char* id, struct entit if (!cJSON_IsNull(brightness)) { out->brightness = brightness->valueint; + + // Zigbee brightness range is 0x01-0xfe. + // Just map 0xfe to 0xff, so at least the slider + // looks full at 100%. + if (out->brightness == 254) + out->brightness = 255; } else { out->brightness = 0; } --- main.c Thu Mar 13 01:51:04 2025 +++ main.c Thu Mar 13 22:02:11 2025 @@ -253,7 +253,7 @@ void bar_create(WindowPtr win, const char* id) nil, true, ent->state.brightness, // current value - 0, 254, + 0, 255, kCustomSliderProc, CONTROL_SLIDER ); @@ -620,7 +620,7 @@ static void bar_draw(struct entity *ent) FrameRect(&barBounds); snprintf(buf, 128, "%d%%", - (val * 100 + 127) / 254); + (val * 100 + 127) / 255); pBuf = c2pstr(buf); width = StringWidth(pBuf);