Add sensors for daylight, night and twilight durations to the sun integration#106936
Add sensors for daylight, night and twilight durations to the sun integration#106936Triple-S wants to merge 6 commits into
Conversation
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @Swamp-Ig, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
You will probably need to add documentation to talk of the new sensors as well ... but I like where you are going with this PR |
…n of the astral package
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Still active and waiting for reply from the maintainers ... |
|
Is there any fundamental problem with this PR? |
|
It looks simple enough -> but the PR time can be VERY VERY long wait |
| STATE_ATTR_DAYLIGHT_DURATION: self.daylight_duration.total_seconds(), | ||
| STATE_ATTR_NIGHT_DURATION: self.night_duration.total_seconds(), | ||
| STATE_ATTR_TWILIGHT_SUNRISE_DURATION: self.twilight_sunrise_duration.total_seconds(), | ||
| STATE_ATTR_TWILIGHT_SUNSET_DURATION: self.twilight_sunset_duration.total_seconds(), |
There was a problem hiding this comment.
There's no need to add these state attributes, it's enough to add the sensors.
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Proposed change
I noticed that although the sun integration provides the times of sunrise and sunset there is no easy way to calculate the length of the current day as the timestamps may correspond to the current or already the next day. There are some workarounds with complicated templates like discussed here: https://community.home-assistant.io/t/hours-of-daylight/59422 but that seems unsatisfactory to me.
In particular as the astral package used in the backend of the sun integration already provides functions to calculate the lengths of day, night and twilight. Furthermore, these calculations are rather inexpensive as they have to be perforemed only once per day. Therefore, I added 4 new sensors to the sun integration which are disabled by default that hold the lengths of the day, the night and the twilight at sunrise and sunset as defined by the astral package.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: