-
-
Notifications
You must be signed in to change notification settings - Fork 1k
SimpleWeatherService: Add sunrise and sunset data #2100
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
base: main
Are you sure you want to change the base?
Conversation
|
Build size and comparison to main:
|
b42424e to
3cf3eb9
Compare
2f6288d to
c7a50f9
Compare
|
Woult it be enough to have the sunset and sunrise in minutes resolution. If so we could define the sunset sunrise timestamps to be in minutes since midnight. Then we only need What do you think? |
|
I like this idea. A quick/naïve implementation would be to truncate the timestamp that Gadgetbridge sends, and we pad it when calculating the actual time, but then the resolution becomes arbitrary. What you're suggesting instead is Gadgetbridge essentially doing something like -long sunriseLocal = weatherSpec.sunRise + Calendar.getOffset("UTC").getTimeInMillis()) / 1000L;
+int sunriseLocal = (weatherSpec.sunRise + Calendar.getOffset("UTC").getTimeInMillis()) / 1000L) / 60;(or whatever the type conversion looks like) I'll give that a try and see what happens. |
|
Ah, nevermind - I see what you're suggesting. Diving the timestamp doesn't really change the size. Math is hard 🤦 |
c7a50f9 to
76a50a4
Compare
76a50a4 to
c57bbee
Compare
c57bbee to
def20a0
Compare
|
To test with InfiniSim with |
def20a0 to
d6ab2e9
Compare
86f3679 to
d06bb24
Compare
d06bb24 to
de7cf7b
Compare
de7cf7b to
a0a9a78
Compare
a0a9a78 to
c302128
Compare
c302128 to
4f2b246
Compare
|
Once this is merged, I'll let the Gadgetbridge folks know so that they can merge the changes on their side (they're waiting for this PR to be merged first). Let me know if there's any change requests here. |
4f2b246 to
7937626
Compare
7937626 to
04b8bc8
Compare
mark9064
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
| - [49, 50] : Sunrise (16 bits, number of minutes elapsed since midnight) | ||
| - [51, 52] : Sunset (16 bits, number of minutes elapsed since midnight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if there is no sunrise or sunset e.g midnight sun at northern latitudes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. This data would be sent from a companion and/or weather app, so it all depends how the apps do this calculation.
Likely it'd be empty (which would cast to 0) or have a negative number. Both cases would lead to the watch showing as daytime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to support the case where it's always night (e.g polar winter). If it gets complex and messy it might not be worth implementing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth implementing. It would require some knowledge of why the sunrise/sunset data is not reported (or reported "differently"), rather than assuming the meaning of an empty/0, which I think is beyond the scope of this app.
Also in the case of a polar winter, worst case here is that weather is reported with a sun icon rather than a moon icon, which is the current behavior anyway (until this is merged at least), so it'd be a no-op in that scenario. 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK cool in that case the only suggestion I have is that the protocol specification should be clear about the expected value when there is no sunrise or sunset, and also when it's unknown.
I would suggest u16 max and then counting backwards (e.g 65535 for unknown, 65534 for no sunset/sunrise event that day) as that allows more flexibility if we want to care more about this later on.
Since there are less than 2^15 minutes in a day, it may also be worth making the field signed in this case as then it's just -1 / -2 which are easier to work with
With this protocol the implementation here could just bail on any negative and assume it's day to avoid the complex edge cases
|
It would be nice to show the sunset/sunrise time to the user in the weather app. PineTime is primarily a clock, so its main purpose is to display the time—in this case, the time of sunset. From my perspective, it’s interesting to know how much time is left until sunset. I have implemented support for the protocol changes introduced here also in Amazfish. |
ba22757 to
6d4e51c
Compare
6d4e51c to
91cc0e5
Compare
145a77b to
6360802
Compare
fccc88c to
fa40b48
Compare
|
Thank you very much for creating and maintaining this PR (in InfiniTime, InfiniSim AND Gadgetbridge!) @vkareh ! Could you confirm that these change do not break the compatibility between InfiniTime and companion apps, thanks to the |
|
@JF002 Good question. With regards to Gadgetbridge, it should always works, since it's based on firmware version detection. The API is additive, so either you have sunrise data or you don't, but the preceding bits are not affected. GB only sends v1 weather data to >=0.15 InfiniTime, else it sends v0 weather. This works in both directions (old IT + new GB; old GB, new IT; etc.) With regards to other companion apps, it depends on whether they check the firmware version:
So basically the only situation in which it would break weather functionality is if the companion app sends version 1 weather without checking what version of InfiniTime it is. |
|
Thanks @vkareh, that looks good to me.
Mhm you are right... This looks like something we could improve in the future : expose the version of the weather API so that companion apps have a easier way to know which version of the messages to send. So I guess this is safe to merge this PR and the one on Gadgetbridge side. |
|
Yeah basically all I wanted with that comment was to formalise the protocol for errors/exceptional cases
So polar day would be sunrise at 0, sunset -2, and polar night sunrise -2, sunset 0 |
|
@mark9064 - this could be nice, but it borders on being an edge case. I think implementing it here is fairly easy, but I'm not sure how to accomplish this in Gadgetbridge if the weather provider doesn't support the concept of polar day/night. |
|
I suppose those corner cases could be indicated as 00:00 or 24:00 — i.e., 0 or 1440 minutes. It would be great to follow how the OpenWeather API or other APIs describe those cases. |
|
I honestly don't know if there's a state of the art for handling days/night without sunrise/sunset. I've never had the opportunity to go to such place :p But yeah, @mark9064 suggestion looks reasonable. Looking at OpenWeather API is another good suggestion from @jmlich. I'm not used to working with the OpenWeather API, but here is how sunrise and sunset are documented : So I guess they return an absolute epoch timestamp for the sunrise and sunset, instead of a relative one from midnight. |
fa40b48 to
c4fe253
Compare
|
@JF002 let me know if you want me to implement this as part of this PR. It would require changes to Gadgetbridge as well. The overall logic would probably look something like:
(same logic for sunset) |
|
To flesh it out, do you mean something like: 0<=x<1440 sunrise happens this many minutes into the day 0<x<1440 sunset happens this many minutes into the day So polar day would be 0,-2 and polar night -2,-2 Not permissible: Note: (x,-2) where x >= 0 valid, this corresponds to a day which has sunrise only. (0,x) corresponds to sunset only Sorry to make this so long... all problems involving date and time seem to have horrible edge cases. My goal here is not to make implementation difficult but instead to have a clear protocol that handles all possibilities. The implementations of the protocol don't need to handle all the edge cases! They could choose to bail on the more complex scenarios. But if we have a clear protocol, then we don't need to upgrade it in future if we decide we do care more about those trickier cases |
|
@vkareh we'd really like to get 1.16 out shortly, do you think you'll be able to look at this soon? |


This receives sunrise and sunset data from the weather service and adapts weather icons to represent the correct time of day (sun or moon).
It requires a new version of the weather service data byte array.