-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Fix Starlink's ever updating uptime #155574
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
Fix Starlink's ever updating uptime #155574
Conversation
|
Hey there @boswelja, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Signed-off-by: David Rapan <[email protected]>
69308fb to
513cc2a
Compare
*This shoud ensure 100% fix Signed-off-by: David Rapan <[email protected]>
b924242 to
118dbab
Compare
Signed-off-by: David Rapan <[email protected]>
Signed-off-by: David Rapan <[email protected]>
a7bf312 to
c1fa9b9
Compare
joostlek
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.
Instead, look at a solution like homewizard did for a similar problem
#150680
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Signed-off-by: David Rapan <[email protected]>
| async def test_last_restart_state(hass: HomeAssistant) -> None: | ||
| """Test Starlink last restart state.""" | ||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={CONF_IP_ADDRESS: "1.2.3.4:0000"}, | ||
| ) | ||
| entity_id = "sensor.starlink_last_restart" | ||
|
|
||
| with ( | ||
| LOCATION_DATA_SUCCESS_PATCHER, | ||
| SLEEP_DATA_SUCCESS_PATCHER, | ||
| STATUS_DATA_SUCCESS_PATCHER, | ||
| HISTORY_STATS_SUCCESS_PATCHER, | ||
| patch( | ||
| "homeassistant.components.starlink.sensor.now", | ||
| return_value=datetime.fromisoformat("2025-10-22T13:31:29+00:00"), | ||
| ), | ||
| ): | ||
| entry.add_to_hass(hass) | ||
|
|
||
| await hass.config_entries.async_setup(entry.entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert entry.runtime_data | ||
| assert entry.runtime_data.data | ||
| assert entry.runtime_data.data.status["uptime"] == 804138 | ||
|
|
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.
Oh right, forgot to tell about the tests.
Ideally we don't touch internals like runtime_data. Also, we shouldn't patch now, and instead use the freezer. I have been playing around this for a little bit to refactor this test to use it, but I didn't have much luck, but that'd be nice if we could have that
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.
Yeah, I kinda wasn't able to make the tests work so this was some sort of a last resort. :) But maybe now we don't need to test it as a sensor and simply test the method?
BTW, I wasn't aware of the ignore_variance wrapper, this is certainly better. 👍
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.
In a way I think having the test test the sensor is best as that's eventually what the user will see, so testing only the method makes it a bit more fragile
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.
678c4dd is the only way I managed to get it working.
Signed-off-by: David Rapan <[email protected]>
Signed-off-by: David Rapan <[email protected]>
Proposed change
Use

ignore_varianceto compare new value against last one w/ 1 minute invariance, so we fix log spam: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.To help with the load of incoming pull requests: