From 1e656c2114d58b96fd7b7750e2e7d255a9175653 Mon Sep 17 00:00:00 2001 From: XS400DOHC <63352197+xs400dohc@users.noreply.github.com> Date: Thu, 13 Feb 2025 17:52:27 +0100 Subject: [PATCH] fix: Home Assistant: add missing `device_class` for some `current` and `power` entities (#26324) --- lib/extension/homeassistant.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index c8a2c1cb..78dd7814 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -1019,6 +1019,14 @@ export default class HomeAssistant extends Extension { if (firstExpose.unit && ['Wh', 'kWh'].includes(firstExpose.unit)) { Object.assign(extraAttrs, {device_class: 'energy', state_class: 'total_increasing'}); } + // If a variable includes A or mA, mark it as current + else if (firstExpose.unit && ['A', 'mA'].includes(firstExpose.unit)) { + Object.assign(extraAttrs, {device_class: 'current', state_class: 'measurement'}); + } + // If a variable includes mW, W, kW mark it as power + else if (firstExpose.unit && ['mW', 'W', 'kW'].includes(firstExpose.unit)) { + Object.assign(extraAttrs, {device_class: 'power', state_class: 'measurement'}); + } let key = firstExpose.name;