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

Only render badge value if there is no icon and no image #10310

Merged
merged 3 commits into from
Oct 17, 2021

Conversation

spacegaier
Copy link
Member

@spacegaier spacegaier commented Oct 17, 2021

Breaking change

Proposed change

The previous condition to check if the value string should be rendered looked at the class members, not at the actually determined values in the render() function.

Also the value string render condition resulted in both icon and value being rendered inside the badge. No the value is only shown if no image or icon is determined.

    badges:
      - entity: climate.test_thermo
      - entity: light.office_ceiling
      - entity: input_number.num_test
      - entity: alarm_control_panel.home_alarm
      - entity: binary_sensor.movement_backyard
      - entity: camera.demo_camera
      - entity: camera.demo_camera
        icon: mdi:police-badge-outline
      - entity: camera.demo_camera
        image: /local/spacegaier.jpg
      - entity: sensor.tablet_a7_akkufullstand
      - entity: sensor.tablet_a7_akkufullstand
        icon: mdi:police-badge-outline
      - entity: person.test_user
      - entity: person.ada

Before: Both badges that have an image are also showing the value plus the third last badge that has an icon defined shows icon and value.
image

After:
image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@@ -96,7 +98,7 @@ export class HaStateLabelBadge extends LitElement {
.description=${this.name ?? computeStateName(entityState)}
>
${!image && icon ? html`<ha-icon .icon=${icon}></ha-icon>` : ""}
${value && (this.icon || !this.image)
${value && !icon && !image
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !icon && !image is technically redundant since I ensured we only determine a value for the same condition further above (to safe some performance) but I felt having this condition again here explicitly makes it more clear.

@spacegaier spacegaier marked this pull request as draft October 17, 2021 20:55
@spacegaier spacegaier marked this pull request as ready for review October 17, 2021 21:01
@spacegaier spacegaier merged commit f0062b1 into home-assistant:dev Oct 17, 2021
@spacegaier spacegaier deleted the issue-10236 branch October 17, 2021 23:39
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HA badge overlaying entity value over entity_picture_template
3 participants