Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix updatedTargets entity id matching #16

Merged
merged 2 commits into from
Dec 8, 2024

Conversation

pugson
Copy link
Contributor

@pugson pugson commented Nov 29, 2024

Error fetching live data when sensors do not end with a matching string.

image
  • updatedTargets is using entity.id.endsWith
  • Home Assistant decided to give my entities IDs such as sensor.everything_presence_lite_hallway_target_2_distance_2
  • as you can see the logic for detecting the correct sensor is broken because mine are ending with “_2”
  • changing endsWith to includes fixes the issue and handles partial string matching
  async function fetchLiveData() {
    ...

    try {
      ...
      const updatedTargets = targetNumbers.map((targetNumber) => {
        // Find corresponding entities for the target
        const activeEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_active`) // <-- endsWith throws an error
        );
        const xEntity = selectedEntities.find((entity) => 
          entity.id.endsWith(`target_${targetNumber}_x`) // <-- endsWith throws an error
        );
        const yEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_y`) // <-- endsWith throws an error
        );
        const speedEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_speed`) // <-- endsWith throws an error
        );
        const resolutionEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_resolution`) // <-- endsWith throws an error
        );
        const angleEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_angle`) // <-- endsWith throws an error
        );
        const distanceEntity = selectedEntities.find((entity) =>
          entity.id.endsWith(`target_${targetNumber}_distance`) // <-- endsWith throws an error
        );
        
        ...

      });

      ...
      
    } catch (error) {
      console.error("Error fetching live data:", error);
      statusIndicator.textContent = "Status: Error Fetching Data";
    } finally {
      isFetchingData = false;
    }
  }

Originally opened as an issue in the wrong repo: EverythingSmartHome/everything-presence-lite#253

@EverythingSmartHome
Copy link
Owner

Thank you!

@EverythingSmartHome EverythingSmartHome merged commit e1ab687 into EverythingSmartHome:main Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants