Skip to content

Add sensors for daylight, night and twilight durations to the sun integration#106936

Closed
Triple-S wants to merge 6 commits into
home-assistant:devfrom
Triple-S:add-daylight-night-twilight-sensors
Closed

Add sensors for daylight, night and twilight durations to the sun integration#106936
Triple-S wants to merge 6 commits into
home-assistant:devfrom
Triple-S:add-daylight-night-twilight-sensors

Conversation

@Triple-S
Copy link
Copy Markdown

@Triple-S Triple-S commented Jan 3, 2024

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

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

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@Triple-S Triple-S requested a review from Swamp-Ig as a code owner January 3, 2024 08:59
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @Triple-S

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Jan 3, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant Bot marked this pull request as draft January 3, 2024 08:59
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Jan 3, 2024

Hey there @Swamp-Ig, mind taking a look at this pull request as it has been labeled with an integration (sun) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of sun can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign sun Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@jeeftor
Copy link
Copy Markdown
Contributor

jeeftor commented Jan 4, 2024

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

Comment thread homeassistant/components/sun/__init__.py Outdated
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
@Triple-S
Copy link
Copy Markdown
Author

Triple-S commented Jan 4, 2024

@jeeftor I added the documentation PR now. I just wanted to get at least some sort of positive reply before I start writing documentation for nothing.
@autinerd Thank you for your review and spotting the typo.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 4, 2024

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Mar 4, 2024
@Triple-S
Copy link
Copy Markdown
Author

Triple-S commented Mar 4, 2024

Still active and waiting for reply from the maintainers ...

@github-actions github-actions Bot removed the stale label Mar 4, 2024
@Triple-S
Copy link
Copy Markdown
Author

Triple-S commented Apr 9, 2024

Is there any fundamental problem with this PR?
I would like to improve it if required, but I need some feedback.

@jeeftor
Copy link
Copy Markdown
Contributor

jeeftor commented Apr 9, 2024

It looks simple enough -> but the PR time can be VERY VERY long wait

Comment on lines +242 to +245
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(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's no need to add these state attributes, it's enough to add the sensors.

@home-assistant home-assistant Bot marked this pull request as draft April 18, 2024 13:11
@github-actions
Copy link
Copy Markdown

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Jun 17, 2024
@github-actions github-actions Bot closed this Jun 26, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 27, 2024
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.

5 participants