fix: ensure activity source config is always respected
This commit is contained in:
parent
626f5399cb
commit
66906f2eed
2 changed files with 15 additions and 2 deletions
|
|
@ -129,7 +129,14 @@ export class EntityDataFetcher {
|
||||||
* @returns {string} Selected activity state
|
* @returns {string} Selected activity state
|
||||||
*/
|
*/
|
||||||
_getActivityToUse(data, entityId, config) {
|
_getActivityToUse(data, entityId, config) {
|
||||||
|
// Safety check for config
|
||||||
|
if (!config) {
|
||||||
|
this._log(`[Warning] No config provided to _getActivityToUse for ${entityId}. Defaulting to sensor.`);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if speed-based prediction is enabled
|
// Check if speed-based prediction is enabled
|
||||||
|
// We use optional chaining and strict equality to ensure we only enter this block
|
||||||
|
// if the user explicitly selected 'speed_predicted'
|
||||||
if (config?.activity_source === 'speed_predicted') {
|
if (config?.activity_source === 'speed_predicted') {
|
||||||
if (data.speed) {
|
if (data.speed) {
|
||||||
// Use predicted activity and cache it for sticky behavior
|
// Use predicted activity and cache it for sticky behavior
|
||||||
|
|
@ -145,6 +152,8 @@ export class EntityDataFetcher {
|
||||||
return lastActivity;
|
return lastActivity;
|
||||||
}
|
}
|
||||||
// Fallback to unknown if no previous predicted activity
|
// Fallback to unknown if no previous predicted activity
|
||||||
|
// IMPORTANT: We return 'unknown' here instead of falling back to sensor
|
||||||
|
// because the user explicitly requested speed-based prediction.
|
||||||
this._log(`Activity for ${entityId}: unknown - speed null, no sticky value`);
|
this._log(`Activity for ${entityId}: unknown - speed null, no sticky value`);
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
@ -162,6 +171,10 @@ export class EntityDataFetcher {
|
||||||
* @returns {Object} Formatted entity data
|
* @returns {Object} Formatted entity data
|
||||||
*/
|
*/
|
||||||
prepareEntityData(config) {
|
prepareEntityData(config) {
|
||||||
|
if (!config) {
|
||||||
|
console.warn('[EntityDataFetcher] prepareEntityData called without config. Activity prediction may be incorrect.');
|
||||||
|
}
|
||||||
|
|
||||||
const entityData = {};
|
const entityData = {};
|
||||||
|
|
||||||
for (const [entityId, data] of Object.entries(this._entityCache)) {
|
for (const [entityId, data] of Object.entries(this._entityCache)) {
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ class MapBadgeCard extends HTMLElement {
|
||||||
this._messenger.sendData(this._pendingData);
|
this._messenger.sendData(this._pendingData);
|
||||||
this._pendingData = null;
|
this._pendingData = null;
|
||||||
} else if (this._dataFetcher.hasData()) {
|
} else if (this._dataFetcher.hasData()) {
|
||||||
this._messenger.sendData(this._dataFetcher.prepareEntityData());
|
this._messenger.sendData(this._dataFetcher.prepareEntityData(this._configManager.getConfig()));
|
||||||
} else {
|
} else {
|
||||||
this._fetchEntities();
|
this._fetchEntities();
|
||||||
}
|
}
|
||||||
|
|
@ -208,7 +208,7 @@ class MapBadgeCard extends HTMLElement {
|
||||||
|
|
||||||
// If data is less than 30 seconds old, retry
|
// If data is less than 30 seconds old, retry
|
||||||
if (now - lastUpdate < 30000) {
|
if (now - lastUpdate < 30000) {
|
||||||
this._messenger.sendData(this._dataFetcher.prepareEntityData());
|
this._messenger.sendData(this._dataFetcher.prepareEntityData(this._configManager.getConfig()));
|
||||||
this._messenger.incrementRetryCount();
|
this._messenger.incrementRetryCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue