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

Bugfix/reintroduce entity element match support #530

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

exetico
Copy link
Member

@exetico exetico commented Mar 24, 2025

  • Fixes a bug, where rules without element key was ignored (but a valid and matching entity in SVG, should be used)
  • Fixes a bug, where the "image" obj was not supported (image_set)
  • Fixes a bug, where our action() function could not be used to image_set with element in service_data

Issue could be reproduced with:

            - entities:
                - light.trodfri5_light
              state_action:
                action: call-service
                service: floorplan.image_set
                service_data:
                  image: |
                    > const states = ['rect-off.svg', 'rect-on.svg'];
                    const randomState = states[Math.floor(Math.random() * states.length)];
                    return `/local/floorplan/__test/${randomState}`;

Fixed, and tested with:

views:
  - title: Modern Home Test
    path: test2
    badges: []
    panel: true
    cards:
      - config:
          console_log_level: debug
          defaults:
            hover_action: hover-info
            tap_action: more-info
          image: /local/floorplan/floorplan1.svg?v=1.1.14
          log_level: info
          rules:
            # Below works, if they're split into two
            - entity: light.trodfri5_light # weather.forecast_home
              state_action:
                  action: call-service
                  service: floorplan.text_set
                  service_data:
                    element: sensor.udestue
                    shift_y_axis: 2em
                    text: ${ entities['weather.forecast_home'].attributes.temperature }${ entities['weather.forecast_home'].attributes.temperature_unit }

            - entity: light.trodfri5_light # weather.forecast_home
              element: sensor.hallway  #<-- element moved out of service_data
              state_action:
                action: call-service
                service: floorplan.image_set
                service_data:
                  image: |
                    > const states = ['rect-off.svg', 'rect-on.svg'];
                    const randomState = states[Math.floor(Math.random() * states.length)];
                    return `/local/floorplan/__test/${randomState}`;

            - entities:
                - light.trodfri5_light
              state_action:
                action: call-service
                service: floorplan.image_set
                service_data:
                  image: |
                    > const states = ['rect-off.svg', 'rect-on.svg'];
                    const randomState = states[Math.floor(Math.random() * states.length)];
                    return `/local/floorplan/__test/${randomState}`;

            - entity: light.trodfri5_light # Located in kitchen... # weather.forecast_home # light.trodfri5_light # This needs to work, even if light.trodfri4_light is usd in other logics
              element: area.guestroom
              name: "BobTest1"
              state_action:
                action: call-service
                service: floorplan.image_set
                service_data:
                  element: area.office
                  image: |
                    > const states = ['rect-off.svg', 'rect-on.svg'];
                    const randomState = states[Math.floor(Math.random() * states.length)];
                    return `/local/floorplan/__test/${randomState}`;

            # This is introduced in 1.0.49 (element as part of service_data)
            - entity: light.trodfri5_light # weather.forecast_home
              state_action:
                - action: call-service
                  service: floorplan.text_set
                  service_data:
                    element: sensor.bob1test
                    shift_y_axis: 2em
                    text: ${ entities['weather.forecast_home'].attributes.temperature }${ entities['weather.forecast_home'].attributes.temperature_unit }
                - action: call-service
                  service: floorplan.image_set
                  service_data:
                    element: sensor.livingroom
                    image: |
                     > const states = ['rect-off.svg', 'rect-on.svg'];
                     const randomState = states[Math.floor(Math.random() * states.length)];
                     return `/local/floorplan/__test/${randomState}`;


            - entities:
                - light.trodfri5_light
              state_action:
                action: call-service
                service: floorplan.image_set
                service_data:
                  element: area.guestroom
                  image: |
                    > // SVG
                    const states = ['rect-off.svg', 'rect-on.svg'];
                    const randomState = states[Math.floor(Math.random() * states.length)];
                    const svgPath = `/local/floorplan/__test/${randomState}`;
                    // Prepare action data 1
                      const action_data_1 = {
                        action: 'call-service',
                        service: 'floorplan.style_set',
                        service_data: {
                          element: 'area.bedroom',
                          style: 'fill: rgb(255,255,255);',
                        }
                      };
                      action(action_data_1);

                    // Prepare action data 2
                      const action_data_2 = {
                        action: 'call-service',
                        service: 'floorplan.image_set',
                        name: 'HIBOB!',
                        service_data: {
                          image: svgPath,
                          element: 'area.udestue',
                          entity: 'light.trodfri5_light',
                        }
                      };
                      action(action_data_2);

                    // Prepare action data 3
                      const action_data_3 = {
                        action: 'call-service',
                        service: 'floorplan.image_set',
                        name: 'HIBOB!',
                        service_data: {
                          image: {location: svgPath, cache: true},
                          element: 'area.restroom',
                          entity: 'light.trodfri5_light',
                        }
                      };
                      action(action_data_3);

                    return svgPath;

                  
          stylesheet: /local/floorplan/floorplan1_main.css?v=1.1.14
        full_height: true
        type: custom:floorplan-card

image

exetico added 2 commits March 24, 2025 17:20
…port image_set in action, including FloorplanImageConfig as config payload
@github-actions github-actions bot added the workflow-modified Pay extra attention to the changes label Mar 24, 2025
@exetico exetico removed the workflow-modified Pay extra attention to the changes label Mar 24, 2025
@ExperienceLovelace ExperienceLovelace deleted a comment from github-actions bot Mar 24, 2025
@exetico exetico merged commit 21376df into master Mar 24, 2025
3 checks passed
@exetico exetico deleted the bugfix/reintroduce_entity_element_match_support branch March 24, 2025 16:27
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.

1 participant