nathan-gs / ha-map-card

A Map Card for Home Assistant
https://community.home-assistant.io/t/map-card-a-slightly-improved-map-card/693088
MIT License
15 stars 4 forks source link

Ability to drive entity history using external entities. #47

Closed thybag closed 1 month ago

thybag commented 1 month ago

See https://github.com/nathan-gs/ha-map-card/issues/45

This PR expands the history exploration features for the MapCard, but allowing history be controlled via external entities. This can be used either as an alternative to the history_date_selection system, or in tandem with it if setup at entity level.

For example if you setup input_number.test_number_value as a helper managed by a custom:numberbox-card card.

type: custom:map-card
history_start: input_number.test_number_value
entities:
  - entity: device_tracker.some_device
  - entity: device_tracker.some_device2

You could also setup an end similarly

type: custom:map-card
history_start: input_number.start_number
history_end: input_number.end_number
entities:
  - entity: device_tracker.some_device
  - entity: device_tracker.some_device2

Custom units can be provided via the following setup

type: custom:map-card
history_start:
  entity: input_number.start_days
  suffix: days ago
history_end:
  entity: input_number.end_days
  suffix: days ago
entities:
  - entity: device_tracker.some_device
  - entity: device_tracker.some_device2

A date entity an also be used rather than a number one if prefered. Suffix only gets added when the state linked is numeric.

All of this can additionally be set at entity level

type: custom:map-card
history_start:
  entity: input_number.start_days
  suffix: days ago
history_end:
  entity: input_number.end_days
  suffix: days ago
entities:
  - entity: device_tracker.some_device
  - entity: device_tracker.some_device2
    history_start:  input_number.differnt_start
    history_end: input_number.differnt_end

Overview of changes

thybag commented 1 month ago

Hi @nathan-gs, think this should hopefully be good to review. Have tested a variety of combos and everything seems happy/working.

What would your thought me on me reorganizing the codebase a bit in a future PR (Breaking it down in to separate files), as with the growing complexity its getting a bit unwieldly all in one. Not 100% if HACS supports distributing multiple files for a single card or whether a simple build step would be required just to inline them all into a dist version.

nathan-gs commented 1 month ago

@thybag thank you! I will review when at a pc.

I was thinking the same, multiple files with a build step to combine. Ideally this way we could also add some unit tests.

Now my experience in the Javascript ecosystem is limited, so will need to do some research.

thybag commented 1 month ago

Please note, if you are happy with the structure changes in https://github.com/nathan-gs/ha-map-card/pull/49, you may be better skipping this PR and merging that instead just to avoid some of the merge conflict fun.

nathan-gs commented 1 month ago

Closing this to continue in #49