Digital-Alchemy-TS / Digital-Alchemy-TS/synapse

Sensor state_class property not flowing through to HA

Open Beginner friendly
#188 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
3
Forks
1
PR merge metrics
No merged PRs in 30d

Description

## 🐜 Bug description

When creating a Sensor, we set a number of properties. Here’s a good example from the docs

```
const power = synapse.sensor({
context,
name: "Living Room Power",
device_class: "power",
unit_of_measurement: "W",
state: 120.5,
state_class: "measurement"
});
```

state_class is important to Home Assistant. I believe this value is needed so a sensor can be added to long term statistics tables. Without it, sensor values are lost depending on the value of purge in config.yaml.

## 📠 Reproduction steps

Running the above code does indeed produce a sensor in HA. But looking in Developer Tools, States, allows us to see the properties of it. state_class is not listed there.

## 🎙️ Additional details

May be useful. Sensor.service.mts doesn’t seem to be including state_class.

const generate = synapse.generator.create({
context,
domain: "sensor",
load_config_keys: [
"device_class",
"state",
"unit_of_measurement",
// conditional
"last_reset",
"suggested_display_precision",
"suggested_unit_of_measurement",
]

Contributor guide

Open the contributing guide

Research direction

Start in Sensor.service.mts and inspect the generator configuration for the sensor properties loaded from the example, comparing it with the documented state_class option. Reproduce the example in Home Assistant and confirm that state_class appears in Developer Tools under States when the work is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.