Skip to content

Harden remaining wrong-service characteristic fallback in history logger (humidity) - #330

Open
7onnie wants to merge 1 commit into
naofireblade:masterfrom
7onnie:fix/hap-strict-mode-characteristic-compliance
Open

Harden remaining wrong-service characteristic fallback in history logger (humidity)#330
7onnie wants to merge 1 commit into
naofireblade:masterfrom
7onnie:fix/hap-strict-mode-characteristic-compliance

Conversation

@7onnie

@7onnie 7onnie commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Related to #317 ("accessory is out of compliance since homebridge 2.0").

The fakegato history logger in index.js reads characteristic values directly off a service. For the humidity value it falls back to CurrentConditionsService.getCharacteristic(Characteristic.CurrentRelativeHumidity) when no dedicated HumidityService exists. Service.getCharacteristic(...) lazily creates and mounts the characteristic if it isn't already present — so when CurrentRelativeHumidity is not on that service, this call silently adds a characteristic that doesn't belong there. Under Homebridge 2.0 / strict HAP, a service carrying a non-conformant characteristic causes the accessory to be flagged out of compliance.

Relationship to #327

PR #327 already hardens the lux fallback in this same block (testCharacteristic(...) ? getCharacteristic(...).value : 0) and bumps fakegato. It does not touch the humidity fallback, which still uses the bare getCharacteristic call. This PR applies the identical, safe guard to the humidity line so the last remaining wrong-service auto-add is closed.

⚠️ This touches the same historyService.addEntry(...) block as #327, so the two will need to be sequenced/rebased. Happy to rebase on top of #327 if you'd prefer to merge that first.

Fix

humidity: accessory.HumidityService
  ? accessory.HumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity).value
  : (accessory.CurrentConditionsService.testCharacteristic(Characteristic.CurrentRelativeHumidity)
      ? accessory.CurrentConditionsService.getCharacteristic(Characteristic.CurrentRelativeHumidity).value
      : 0),

testCharacteristic(name) is a side-effect-free existence check (HAP-NodeJS Service.testCharacteristic), so it never mounts anything. When the characteristic genuinely exists the real value is logged; otherwise 0 is used, matching the existing pressure/lux : 0 idiom.

Trigger scope

The fallback branch is only reached when there is no HumidityService and CurrentRelativeHumidity was not mounted on the main service (e.g. Humidity placed in the hidden config). It is narrow, but it is a real, deterministic out-of-compliance trigger.

Validation (no hardware required)

testCharacteristic confirmed side-effect-free against HAP-NodeJS Service source. node --check passes on the changed file (repo is plain CommonJS, no build/lint/test). One-line change; no secrets in the diff.

…tory fallback (naofireblade#317)

When no separate HumidityService exists, the history logger fell back to
accessory.CurrentConditionsService.getCharacteristic(CurrentRelativeHumidity).
HAP-NodeJS lazily creates and attaches a characteristic on getCharacteristic(),
so in modes where the main service is a bare TemperatureSensor (e.g. eve with
extraHumidity) this silently mounts CurrentRelativeHumidity onto a service that
does not permit it, tripping Homebridge 2.0 / iOS strict HAP validation
("Accessory out of compliance").

Guard the fallback with testCharacteristic() so the value is only read when the
characteristic is legitimately present (eve, eve2, default modes still log the
real value), and fall back to 0 otherwise instead of polluting the service.
Mirrors the existing :0 guards already used for pressure and lux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant