Open
Conversation
97d1eb5 to
59a22b4
Compare
Previous implementations did not handle edge cases very well and were still broken.
0c1c681 to
c9ecc27
Compare
Change 0.833 to 0.267 for elevation of sun below horizon at sunrise & sunset. This changed when the astral package changed from 1.10.1 to 2.0 & later, which was used in HA starting w/ 2021.5.0b0.
Also move more common code into base classes.
fa84cb0 to
3f8fd24
Compare
Split out most of Sun2EntityWithElvAdjs into Sun2EntityWithElvParams. Add moving to nearest second back to elevation binary sensor. Miscellaneous cleanup.
0b80096 to
88ea8a5
Compare
Differences between solar_elevation & time_at_elevation were causing next elevation target to repeat for multiple updates. Using target prevents this. And an analysis over several days shows that the difference between target & actual were no more than about 0.25 degrees.
Also remove str from type of Sun2PointInTimeSensor class since it can only result in a datetime (or None.) This was actually changed a long time ago, but the type was not adjusted accordingly.
Sun2Entity class assumed async_update & anything called via async_request_call were protected by a semaphore to make them atomic, but platform modules did not define the required PARALLEL_UPDATES attribute. This change fixes that by adding it to binary_sensor.py & sensor.py. Elevation sensor uses "raw", unrounded elevation for state instead of "target" value. This is potentially a breaking change since users/automations might depend on value (mostly) being a multiple of 0.5 degrees. However, this can easily be compensated for by using the states function w/ rounding=True in a template. This allows users to set the display precision differently than the default value of one decimal place. Change Sun2ElevationSensor in binary_sensor.py to Sun2ElevationBinarySensor to differentiate from Sun2ElevationSensor in sensor.py.
Make Sun2ElevationBinarySensor._update and Sun2PointInTimeSensor._update yield approximately every 50 milliseconds.
…ethods These methods were found to be calculating results for the same date multiple times. Round timestamp states (and yesterday, today & tomorrow attributes) to nearest second.
Update every 2 min within 6 degrees of sunrise/sunset and every 10 min otherwise.
When config changes, only update entities that are enabled.
Do not force removal of suggested_display_precision from PeriodOfTimeSensor entities because, 1) it's no longer needed, and 2) the core sensor logic keeps changing it back to 2.
Improve Sun2Entity._log_name.
3b88b6b to
3b2f73e
Compare
Avoid using astral's local time zone conversion because it uses pytz whereas self._as_tz uses HA's zoneinfo implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make sensors use observer elevation that should but haven't before
Simplify implementations using
time_at_elevationinstead of searching "elevation curve"Miscellaneous changes
_updatemethod async so potentially long running implementations (such as inSun2ElevationBinarySensorandSun2PointInTimeSensor) can be split up so as not to suck up too much CPU time.PARALLEL_UPDATES = 1tobinary_sensor.py&sensor.py.Location.midnight&Location.noon, since these results are (re)used by many entities. Also helps reduce configuration reload time.suggesed_display_precisionfromPeriodOfTimeSensorentity registry entries, since core code just sets it back to 2. The force removal, that was added to work around a core issues, is no longer needed.homeassistant.update_entityservice/action correctly, or ignore it.Breaking Changes
unknownpreviously. The attributes (yesterday, today & tomorrow) still behave as they did before (i.e., their value will be None/null if the event does not occur on the given day.)states(binary_sensor.xxx, rounded=True).