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

Calculation and graph overhaul + Moon support #56

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

avataar
Copy link
Collaborator

@avataar avataar commented Jul 5, 2023

Summary of changes:

  • Completely revamped calculations and Sun graph, now way more realistic
  • Moon support: Moon on the graph, moonrise, moonset, Moon phase, Moon elevation and Moon azimuth
  • Obeys Home Assistant's settings for time and number formatting
  • Cleaned up config options
  • Font size adjustments, including the smaller AM/PM text from the original card
  • Lots of tests
  • All lint warnings gone

Resolves the following issues:

Thanks to @MiisaTrAnCe, @lcnittl, @edwardtfn, @4l4R1, @HydrelioxGitHub, @v1k70rk4, @lcnittl, @JasringStw, @tjorim, @HepoH3 and @v1k70rk4 for helping with translations for the new moonrise/moonset labels.

Note that I've also translated all existing languages where a contribution for the new labels was missing and I used Google Translate, plain old Google, Wikipedia, common sense and my own nerdiness for languages but some things might still be slightly off. I also corrected the sunrise/sunset labels for Malay as they were the labels for dusk/dawn instead (and I coincidentally learned that "matahari" means Sun in Malay and that's where Mata Hari got her stage name from!).

@avataar
Copy link
Collaborator Author

avataar commented Jul 5, 2023

Here is a built version for those who wish to test this but can't build it themselves (needs to be installed manually in HASS):
lovelace-horizon-card.zip.

@avataar
Copy link
Collaborator Author

avataar commented Jul 5, 2023

Looking for brave souls who'd review/test this: @edwardtfn, @ThomDietrich, anyone!

@HepoH3
Copy link

HepoH3 commented Jul 5, 2023

Looking for brave souls who'd review/test this: @edwardtfn, @ThomDietrich, anyone!

Thank you for you work!
Here is how it looks like to me (I played a bit with my PC time to get different results):
изображение
изображение
изображение

@avataar
Copy link
Collaborator Author

avataar commented Jul 5, 2023

@HepoH3, thanks, looks good! Check out the now option too, it will allow you to set a static time just for the card so you can get different looks without messing with the clock :) And of course the various fields options that show new Moon data.

@HepoH3
Copy link

HepoH3 commented Jul 6, 2023

@HepoH3, thanks, looks good! Check out the now option too, it will allow you to set a static time just for the card so you can get different looks without messing with the clock :) And of course the various fields options that show new Moon data.

Moon fields looking good too (but I needed about five minutes to figure out that I'm missing fields option).
изображение

The now option didn't work for me (I think I'm doing something wrong). I created a helper input_datetime object, and put it into now field which brokes everything:

изображение

  - type: custom:horizon-card
    moon: true
    fields:
      moonrise: true
      moonset: true
      moon_phase: true
    # now: input_datetime.test_date

I think there should be an example of full card config.

@JasringStw
Copy link

took me a moment to get the config right in HA but have it now, looks good. one comment is that maybe the title for the moon_phase should also be above the picture
CleanShot 2023-07-06 at 11 00 49@2x

@ThomDietrich
Copy link

ThomDietrich commented Jul 6, 2023

@JasringStw the position makes sense to me, as "afnemende maan" is the actual moon phase, i.e. state rather than title!? However, because of that the text color would need to be black rather than gray @avataar ?

@wwwescape
Copy link

wwwescape commented Jul 6, 2023

Works great but I have one request which was from the older card as well. Could the English translations be in title case?

I was wondering if an option like use_title_case would be useful but I wasn't sure how this would affect other languages.

Either way, I could create a PR once this is merged or maybe this PR could be updated with it. 😁

image

@v1k70rk4
Copy link

v1k70rk4 commented Jul 6, 2023

It looks perfect in Hungarian, but the moon phase text is not visible here. Though it's strange that I can't see it either in English or Dutch :)

I put in the following configuration:

type: custom:horizon-card
language: hu
moon: true
fields:
  sunrise: true
  sunset: true
  dawn: true
  noon: true
  dusk: true
  elevation: true
  moonrise: true
  moonset: true
  moon_phase: true
  azimuth: true

image

@avataar
Copy link
Collaborator Author

avataar commented Jul 6, 2023

Thank you all for testing! I just pushed some fixes based on your comments:

  • @HepoH3, the README now has an example config section showing the full config. The now should be something of the sort 2023-07-06T00:30:05+0300
  • @JasringStw and @ThomDietrich, I kept the Moon phase where it was but changed the colour to match the rest of the values
  • @v1k70rk4, that was a tricky one but I figured it out. The Moon phase names come from Home Assistant's Moon integration and I'm pretty sure you don't have that enabled. I've changed the implementation to show the non-translated constant like waning_gibbuous (!) (and if you hover it with the mouse, a tooltip that explains the reason). I also added a Caveats section in the README that explains the peculiarities of Moon phase, including that it will be shown in HA's language and not the card language (if different). @HepoH3, your screenshots indicate the same problem.

I also removed the dark_mode option from the README as it's buggy - too many styles get inherited directly from Home Assistant. So you just get the same theme as your Home Assistant and I believe that's good enough.

New zip with the changes: lovelace-horizon-card.zip

@wwwescape, let's keep the title case thing for the near future after this is merged.

@v1k70rk4
Copy link

v1k70rk4 commented Jul 6, 2023

  • @v1k70rk4, that was a tricky one but I figured it out. The Moon phase names come from Home Assistant's Moon integration and I'm pretty sure you don't have that enabled. I've changed the implementation to show the non-translated constant like (and if you hover it with the mouse, a tooltip that explains the reason). I also added a Caveats section in the README that explains the peculiarities of Moon phase, including that it will be shown in HA's language and not the card language (if different). @HepoH3, your screenshots indicate the same problem.waning_gibbuous (!)

Thank you very much for your work. Indeed, the moon integration was not enabled. Now the colors and texts are perfect!

image

@wwwescape
Copy link

Thank you all for testing! I just pushed some fixes based on your comments:

...

@wwwescape, let's keep the title case thing for the near future after this is merged.

@avataar No problem. I can wait. Thanks for all the work!

@ThomDietrich ThomDietrich added the release:major (X.x.x) Bump semantic version and release a build to HACS label Jul 7, 2023
@wwwescape
Copy link

wwwescape commented Jul 8, 2023

Thank you all for testing! I just pushed some fixes based on your comments:
...
@wwwescape, let's keep the title case thing for the near future after this is merged.

@avataar No problem. I can wait. Thanks for all the work!

We may not need the title case option after all! I managed to get the titles and values title cased by styling them using lovelace-card-mod:

card_mod:
  style: |
    .horizon-card-field-name, .horizon-card-field-value {
      text-transform: capitalize;
    }

@v1k70rk4
Copy link

What needs to happen now for us to proceed? Or is there perhaps an issue? (I'm just asking out of curiosity :) )

@avataar
Copy link
Collaborator Author

avataar commented Jul 12, 2023

What needs to happen now for us to proceed? Or is there perhaps an issue? (I'm just asking out of curiosity :) )

I've addressed all issues that were reported here + a fix for the recently opened issue #58 related to a new TZ setting in HA 2023.7.

Other than someone brave looking at the code there is nothing that prevents us from merging this :)

@@ -0,0 +1,25 @@
# Local copy of suncalc3

This is a copy of module suncalc3 v2.0.5 with some minor modifications that bypass its wrong assumptions about time zones.

Choose a reason for hiding this comment

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

Seems like an extreme step. Did you raise those wrong assumptions, do you see a path to remove this local copy at a later state?

Copy link
Collaborator

Choose a reason for hiding this comment

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

"its incorrect assumptions", or "imprecise", sounds better than "wrong". 😉
"some minor modifications to improve its time zone handling."?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ThomDietrich, extreme or not it was very necessary. When I find the time I might submit a PR to the original project but I really needed it to work in an "improved" way :)

@edwardtfn, wrong is wrong whether you call it that or "incorrect". But I get your point so I changed it to "improve its time zone handling".

Copy link

@ThomDietrich ThomDietrich left a comment

Choose a reason for hiding this comment

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

Amazing work!

@ThomDietrich
Copy link

@edwardtfn would you like to leave a review?

This is an amazing addition to the project and I am more than happy to support its merge. @avataar please proceed with the merge, tagging, versioning and release notes as you see fit :)


- Home Assistant reports the time of the next occurring Sun event. For example, if you look at the card during the day, the time for sunrise will reflect tomorrow's sunrise and not the one that occurred on the same day.
### Caveats

Copy link
Collaborator

Choose a reason for hiding this comment

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

"... followed by (!)", right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good spot! Fixed.

- Completely revamped calculations and Sun graph, now way more realistic
- Moon support: Moon on the graph, moonrise, moonset, Moon phase, Moon elevation and Moon azimuth
- Obeys Home Assistant's settings for time and number formatting
- Cleaned up config options
- Font size adjustments, including the smaller AM/PM text from the original card
- Lots of tests
- All lint warnings gone

Resolves the following issues:
- #11 - Moon support
- #30 - Horizon-card customize with card-mod
- #40 - More realistic visualization and own source of Sun data
- #54 - 24h format not working by default
- #58 - Support HA 2023.7's local/server time zone setting
@avataar avataar force-pushed the major-overhaul-and-moon-support branch from 601ab84 to dc9971b Compare July 13, 2023 17:23
@avataar avataar merged commit bd25747 into main Jul 13, 2023
@avataar avataar deleted the major-overhaul-and-moon-support branch July 13, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:major (X.x.x) Bump semantic version and release a build to HACS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants