Hypfer / lovelace-valetudo-map-card

Display the map from a valetudo-enabled robot in a home assistant dashboard card.
MIT License
243 stars 36 forks source link

Avoid duplicate element definition if already defined #153

Closed sqozz closed 5 months ago

sqozz commented 5 months ago

I realized that this card produces error messages in my javascript console because it tries to define the element valetudo-map-card a second time. Looking at my network tab in Firefox I can see, that it is once loaded from /local/community/lovelace-valetudo-map-card/valetudo-map-card.js and a second time from /hacsfiles/lovelace-valetudo-map-card/valetudo-map-card.js.

As far as I can tell this is wanted behavior of home-assistant/hacs. I also checked another popular lovelace card and there I found the same approach: https://github.com/piitaya/lovelace-mushroom/blob/48db88d906be1301da6d2bfe2b259a704399c225/src/cards/chips-card/chips/conditional-chip.ts#L61-L64

This PR implements a check before the element gets defined and skips the step if already present.