feat(homebridge): HomeKit-native presence/safety/energy-continuity tranche - #87
Conversation
…anche Ships items 1-4 of the captain-picked capability-expansion menu (item 5, Powerwall battery, was already constructed on this channel - verified, no change needed): - Vehicle home/work OccupancySensor presence (favourite opt-in via enableFavoritePresence), created only once a field actually reports a value and debounced against geofence-boundary flicker. Only the semantic booleans are consumed, never raw coordinates. - TPMS warning contact sensors: one aggregate critical-warning sensor plus four per-wheel soft-warning sensors. StatusFault stays set until a real warnings payload arrives, so a missing reading is never mistaken for "safe". - Grid outage and active Storm Watch contact sensors driven by live_status, distinct from the existing Storm Watch settings switch. - Wall Connector fault and vehicle-connected contact sensors per DIN. Fault code zero clears, nonzero sets; no wattage is exposed. No custom UUIDs or numerics shoehorned into unrelated characteristics.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a8b523e51b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const anyHardWarning = | ||
| warnings.front_left || warnings.front_right || warnings.rear_left || warnings.rear_right; |
There was a problem hiding this comment.
Include every Semi axle in the TPMS warning result
For a Tesla Semi, the generated TpmsHardWarnings payload also contains six semi_* axle flags, but this expression ignores them and can clear the aggregate critical-warning sensor while one of those tyres has a hard warning. Either include every warning field or gate this four-wheel implementation away from Semi vehicles.
AGENTS.md reference: AGENTS.md:L140-L140
Useful? React with 👍 / 👎.
| gridStatus === "Active" ? ContactSensorState.CONTACT_DETECTED : ContactSensorState.CONTACT_NOT_DETECTED, | ||
| ); | ||
| this.service.updateCharacteristic(StatusFault, StatusFault.NO_FAULT); |
There was a problem hiding this comment.
Preserve the unknown grid state instead of reporting an outage
When grid_status is the documented "Unknown" enum value, this ternary reports the grid as down and the next line clears StatusFault. That turns unavailable grid telemetry into a definite outage and can trigger false HomeKit automations; only "Inactive" should indicate an outage, while "Unknown" should retain an unknown/faulted state.
AGENTS.md reference: AGENTS.md:L142-L142
Useful? React with 👍 / 👎.
| const { ContactSensorState } = this.platform.Characteristic; | ||
|
|
||
| // Fault code 0 clears the fault contact; any nonzero code sets it. | ||
| const faultCode = connector.wall_connector_fault_state ?? 0; |
There was a problem hiding this comment.
Leave omitted Wall Connector fault states unknown
For a connector entry that omits the optional wall_connector_fault_state, ?? 0 reports a confirmed no-fault condition even though no fault reading was received. This can hide an unavailable fault signal; initialize the sensor with StatusFault.GENERAL_FAULT and only clear/update it when the field is actually present.
AGENTS.md reference: AGENTS.md:L142-L142
Useful? React with 👍 / 👎.
|
|
||
| // HA only creates located_at_favorite when the user has opted in; mirror | ||
| // that instead of surfacing a third sensor by default. | ||
| if (this.platform.config.enableFavoritePresence) { |
There was a problem hiding this comment.
Remove the favorite sensor when its opt-in is disabled
If a user previously enabled favorite presence and later disables it, Homebridge restores the already-cached presence-favorite service before this constructor runs. Skipping the definition only stops new updates; it never removes that service, so the opt-out remains exposed indefinitely with its last occupancy value. Explicitly remove any cached favorite service when the setting is false.
AGENTS.md reference: AGENTS.md:L140-L140
Useful? React with 👍 / 👎.
| for (const connector of connectors as WallConnectorStatus[]) { | ||
| if (!connector?.din) continue; | ||
| this.updateConnector(connector); | ||
| } |
There was a problem hiding this comment.
Retire Wall Connector services that disappear from status
When a DIN is removed from a later complete wall_connectors array—or a cached accessory is restored after that hardware was removed—this loop only updates current entries and never removes the old DIN's two HAP services. Those sensors therefore remain exposed forever with stale connected/fault values; reconcile tracked and cached Wall Connector subtypes against each received list.
AGENTS.md reference: AGENTS.md:L142-L142
Useful? React with 👍 / 👎.
Ships items 1-4 of the captain-picked HomeKit capability-expansion menu (item 5, Powerwall battery, was already constructed on this channel - verified, no change needed).
OccupancySensorpresence (favourite location opt-in viaenableFavoritePresence, matching HA's own opt-in treatment). Each sensor is created only once its field actually reports a value - one withheld by missing location scope is simply never created - and transitions after that are debounced against geofence-boundary flicker. Only the semantic home/work/favourite booleans are consumed, never raw coordinates.StatusFaultstays set until a real warnings payload arrives, so a missing reading is never mistaken for "safe". No pressure numerics anywhere - HomeKit has no honest characteristic for those.live_status, distinct from the existing Storm Watch settings switch (a setting being enabled isn't the same as it currently being active).Everything here uses standard HomeKit services and characteristics only - no custom UUIDs, no numerics shoehorned into
Temperature/Brightness.Test plan
pnpm --filter homebridge-teslemetry tscpnpm --filter homebridge-teslemetry test(133 passing, including new coverage for all five new services)pnpm --filter homebridge-teslemetry buildpnpm lint