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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Astral to 2.2 #48573

Merged
merged 2 commits into from
Apr 1, 2021
Merged

Upgrade Astral to 2.2 #48573

merged 2 commits into from
Apr 1, 2021

Conversation

FMKaiba
Copy link
Contributor

@FMKaiba FMKaiba commented Apr 1, 2021

Breaking change

  • If you're writing custom integrations and are using our sun helper, you will need to update your code. The sun helper has changed its signature for get_astral_location and get_location_astral_event_next to include an elevation parameter. Also the return value of get_astral_location has changed to a tuple including elevation.
@callback
@bind_hass
def get_astral_location(
    hass: HomeAssistant,
) -> tuple[astral.location.Location, astral.Elevation]:
    """Get an astral location for the current Home Assistant configuration."""

@callback
def get_location_astral_event_next(
    location: astral.Location,
    location: astral.location.Location,
    elevation: astral.Elevation,
    event: str,
    utc_point_in_time: datetime.datetime | None = None,
    offset: datetime.timedelta | None = None,
) -> datetime.datetime:
    """Calculate the next specified solar event."""

The reason for the breaking change is that we've updated the astral library used in Home Assistant Core from version 1.10.1 to version 2.2. Please see the changelog of astral for further details:
https://github.com/sffjunkie/astral/blob/master/ChangeLog.md#22---2020-05-20

Proposed change

Updates the Astral Package to 2.2. This assists users running home-assistant on distros with dependancies attached to a more recent version of Astral such as seen in Arch linux

https://github.com/sffjunkie/astral/blob/master/ChangeLog.md#22---2020-05-20

sffjunkie/astral@1.10.1...2.2

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

Differences between Astral 2.2 and 1.10.1
sffjunkie/astral@1.10.1...2.2
See Version Changes at this link for main differences
https://astral.readthedocs.io/en/latest/index.html

@FMKaiba
Copy link
Contributor Author

FMKaiba commented Apr 1, 2021

Tests adjusted to match the output of the new Astral 2.2.
As new astral is more accurate ( down to ms ) adjusted rounding of tasks.
Code removed from TOD that solved issues from previous version of astral that is no longer needed and causes issues with new version

@@ -152,10 +155,10 @@ async def test_norway_in_june(hass):

assert dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_RISING]
) == datetime(2016, 7, 25, 23, 23, 39, tzinfo=dt_util.UTC)
) == datetime(2016, 7, 24, 22, 59, 45, 689645, tzinfo=dt_util.UTC)
Copy link
Member

Choose a reason for hiding this comment

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

Why does this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(copy-paste of relevant information from above)
The new Astral both produces different times and provides times down to the MS level. To deal with that the tests need to be re-written. Tests were written to match old Astrals less accurate data.

I got confirmation here:
#48282 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

The difference looks to be more than 24 hours. So it shouldn't just be the milliseconds accuracy. Can you explain the other differences that would result in this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, this confused and stumped me for some time. Long story short, since the day goes on for more than a month, it seems many calculators are in disagreement as to the date of sunrise and sunset here.

For example:
https://www.timeanddate.com/sun/norway/tromso?month=6&year=2016
https://www.esrl.noaa.gov/gmd/grad/solcalc/table.php?lat=69.6&lon=18.8&year=2016

It seems both versions of astral are wrong, but is entirely dependant on the altitude specified, as the sun barely makes it to the 7 degree inclination required for it to be considered a sunrise, the more altitude you add the sooner time the sunrise is ( in this case even by almost a day! ) The new version of Astral uses the location of the user ( via hass config ) to calculate times, as such the sunrise and sunset times will vary because of that. You will see I made edits to the tests in many places to specify a location's elevation ( based off the elevation at that latitude and longitude of coordinates ) as to increase the accuracy of apparent sunrise.

tests/components/sun/test_trigger.py Show resolved Hide resolved
tests/components/tod/test_binary_sensor.py Show resolved Hide resolved
tests/helpers/test_sun.py Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Dev automation moved this from Needs review to Reviewer approved Apr 1, 2021
@MartinHjelmare MartinHjelmare merged commit 09eb74f into home-assistant:dev Apr 1, 2021
Dev automation moved this from Reviewer approved to Done Apr 1, 2021
@pnbruckner
Copy link
Contributor

This is a breaking change since the API of both the astral package and homeassistant.helpers.sun have changed. E.g., it breaks my "sun2" custom integration. It would be good to mark this as such.

@MartinHjelmare
Copy link
Member

It's not a breaking change for users, but it's a breaking change for custom integration developers.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants