Skip to content

feat(homebridge): HomeKit-native presence/safety/energy-continuity tranche - #87

Merged
Bre77 merged 1 commit into
mainfrom
fm/hb-tranche-native-batch
Aug 3, 2026
Merged

feat(homebridge): HomeKit-native presence/safety/energy-continuity tranche#87
Bre77 merged 1 commit into
mainfrom
fm/hb-tranche-native-batch

Conversation

@Bre77

@Bre77 Bre77 commented Aug 3, 2026

Copy link
Copy Markdown
Member

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).

  • Vehicle home/work OccupancySensor presence (favourite location opt-in via enableFavoritePresence, 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.
  • 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". No pressure numerics anywhere - HomeKit has no honest characteristic for those.
  • Grid outage and active Storm Watch contact sensors driven by live_status, distinct from the existing Storm Watch settings switch (a setting being enabled isn't the same as it currently being active).
  • Wall Connector fault and vehicle-connected contact sensors, one accessory subtype pair per DIN. Fault code zero clears the contact, nonzero sets it; connected state derives from the connector's plug state. No wattage is exposed.

Everything here uses standard HomeKit services and characteristics only - no custom UUIDs, no numerics shoehorned into Temperature/Brightness.

Test plan

  • pnpm --filter homebridge-teslemetry tsc
  • pnpm --filter homebridge-teslemetry test (133 passing, including new coverage for all five new services)
  • pnpm --filter homebridge-teslemetry build
  • pnpm lint

…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.
@Bre77 Bre77 added the fm Opened by a Firstmate crewmate label Aug 3, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +87 to +88
const anyHardWarning =
warnings.front_left || warnings.front_right || warnings.rear_left || warnings.rear_right;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +40 to +42
gridStatus === "Active" ? ContactSensorState.CONTACT_DETECTED : ContactSensorState.CONTACT_NOT_DETECTED,
);
this.service.updateCharacteristic(StatusFault, StatusFault.NO_FAULT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +43 to +46
for (const connector of connectors as WallConnectorStatus[]) {
if (!connector?.din) continue;
this.updateConnector(connector);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Bre77
Bre77 merged commit 2c6a035 into main Aug 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fm Opened by a Firstmate crewmate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant