Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions custom_components/dte_rates/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import defaultdict
from decimal import Decimal

from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, SensorStateClass
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components import persistent_notification
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -76,7 +76,6 @@ async def async_setup_entry(
class _DteBaseRateSensor(CoordinatorEntity, SensorEntity):
_attr_native_unit_of_measurement = "USD/kWh"
_attr_device_class = SensorDeviceClass.MONETARY
_attr_state_class = SensorStateClass.MEASUREMENT

def __init__(self, coordinator, entry: ConfigEntry) -> None:
super().__init__(coordinator)
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Current research notes:

- `research/rider18-export-rates.md` - Rider 18 export-rate source mapping and PSCR formula decisions.
- `research/issue-3-rate-modifiers.md` - PSCR/tax modifier defaults and calculation scope for real out-of-pocket rates.
- `research/issue-5-entity-type.md` - Home Assistant monetary sensor state-class warning and entity metadata decision.
27 changes: 27 additions & 0 deletions docs/research/issue-5-entity-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Issue 5 Entity Type Warning

## Source

- GitHub issue: https://github.com/javaDevJT/DTE-Rates-for-Home-Assistant/issues/5
- Title: Entity type issue
- Created: 2026-05-29

## Report

Home Assistant logs warnings for `DteImportRateSensor` and `DteExportRateSensor`:

`device_class: monetary` was combined with `state_class: measurement`.

Current Home Assistant sensor validation rejects that combination. Monetary sensors may have no state class, or use state class `total` when the entity represents a total amount. These rate sensors represent a current price in `USD/kWh`, not an accumulating monetary total.

## Decision

- Keep `device_class: monetary`.
- Keep `native_unit_of_measurement: USD/kWh`.
- Remove `state_class` from the import/export price sensors.

This preserves the current-price entity shape while avoiding invalid long-term statistics metadata.

## Reference

- Home Assistant sensor developer docs: https://developers.home-assistant.io/docs/core/entity/sensor/
17 changes: 17 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ def test_import_sensor_returns_default_out_of_pocket_rate(monkeypatch):
}


def test_rate_price_sensors_do_not_set_invalid_monetary_state_class(monkeypatch):
monkeypatch.setattr("custom_components.dte_rates.sensor.dt_util.now", lambda: datetime(2026, 3, 1, 12, 0))

coordinator = _coordinator_with_rate()
entry = SimpleNamespace(entry_id="entry_18", data={CONF_SELECTED_RATE: "D1.11", CONF_NET_METERING: False})

import_sensor = DteImportRateSensor(coordinator, entry)
export_sensor = DteExportRateSensor(coordinator, entry)

assert getattr(import_sensor, "_attr_device_class", None) == "monetary"
assert getattr(export_sensor, "_attr_device_class", None) == "monetary"
assert import_sensor.native_unit_of_measurement == "USD/kWh"
assert export_sensor.native_unit_of_measurement == "USD/kWh"
assert getattr(import_sensor, "_attr_state_class", None) is None
assert getattr(export_sensor, "_attr_state_class", None) is None


def test_import_sensor_can_omit_modifiers(monkeypatch):
monkeypatch.setattr("custom_components.dte_rates.sensor.dt_util.now", lambda: datetime(2026, 3, 1, 12, 0))

Expand Down
Loading