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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions packages/eviqo-mqtt/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import {
getTopicId,
} from './ha-discovery';

/**
* Session entity names - these are only updated during charging
*/
const SESSION_ENTITIES = new Set(['Session duration', 'Session power', 'Session cost']);

/**
* Value transformers for specific widgets
* Maps widget name to a function that transforms the raw value
Expand Down Expand Up @@ -404,6 +409,15 @@ export class EviqoMqttGateway extends EventEmitter {
// Only publish widgets that have a mapping defined
if (!isInWidgetMappings && !controlSettings) return;

// Session entities are only updated during charging
if (SESSION_ENTITIES.has(widgetName)) {
const currentStatus = this.deviceStatus.get(String(deviceId));
if (currentStatus !== '2') {
logger.debug(`Skipping ${widgetName} update for device ${deviceId}: not charging (status=${currentStatus})`);
return;
}
}

// Apply value transformer if one exists for this widget
const transformer = VALUE_TRANSFORMERS[widgetName];
const publishValue = transformer ? transformer(rawValue) : rawValue;
Expand Down
Loading