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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve availability of Tractive entities #97091

Merged
merged 11 commits into from Aug 17, 2023
Merged

Improve availability of Tractive entities #97091

merged 11 commits into from Aug 17, 2023

Conversation

bieniu
Copy link
Member

@bieniu bieniu commented Jul 23, 2023

Breaking change

Proposed change

Sometimes the API returns null instead of values, this causes the sensor state to be unknown.

Zrzut ekranu 2023-07-23 171225

Also this may cause warnings for sensors that have numeric values as states and have a defined state_class.

With this change, entities are marked as unavailable during init and when an event with data is received, their availability is determined based on the condition value is not None. If the value is None, the entity will be unavailable.

Also, the handle_server_unavailable() and handle_status_update() functions have been moved to TractiveEntity to simplify the code.

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 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.
  • 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:

@home-assistant
Copy link

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

Code owner commands

Code owners of tractive 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 tractive Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@bieniu bieniu marked this pull request as ready for review July 23, 2023 16:25
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jul 23, 2023
@bieniu bieniu marked this pull request as draft July 24, 2023 06:40
@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Jul 24, 2023
@bieniu
Copy link
Member Author

bieniu commented Jul 24, 2023

I think we have a race condition here, on my production system the entities after HA start are unavailable for 2-3 minutes. Probably entities are taking too long to initialize and are not getting the first events with data from TractiveClient. Probably this was also the reason for the previously unknown states. I think there was once an issue related to this, a user reported that switches are unavailable right after HA starts. @Danielhiversen @zhulik Do you have an idea how we can fix that?

@bieniu
Copy link
Member Author

bieniu commented Aug 4, 2023

Now the event subscription starts when entities are initialized. On my production system, entities are available 2-3 seconds after HA starts.

@bieniu bieniu marked this pull request as ready for review August 4, 2023 13:04
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @bieniu 👍

My requested changes are only small code style improvements :)

homeassistant/components/tractive/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/tractive/binary_sensor.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

home-assistant bot commented Aug 4, 2023

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 August 4, 2023 15:00
@bieniu bieniu marked this pull request as ready for review August 5, 2023 13:37
@home-assistant home-assistant bot requested a review from edenhaus August 5, 2023 13:37
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

I found a slight improvement. What do you think about it?

homeassistant/components/tractive/entity.py Show resolved Hide resolved
homeassistant/components/tractive/sensor.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 8, 2023 07:57
@bieniu bieniu marked this pull request as ready for review August 8, 2023 09:51
@home-assistant home-assistant bot requested a review from edenhaus August 8, 2023 09:51
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Some minor improvements to remove the assert.

homeassistant/components/tractive/entity.py Show resolved Hide resolved
homeassistant/components/tractive/entity.py Outdated Show resolved Hide resolved
homeassistant/components/tractive/entity.py Outdated Show resolved Hide resolved
homeassistant/components/tractive/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/tractive/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/tractive/switch.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 16, 2023 17:38
@bieniu bieniu marked this pull request as ready for review August 17, 2023 09:48
@home-assistant home-assistant bot requested a review from edenhaus August 17, 2023 09:48
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @bieniu 🚀

@edenhaus edenhaus merged commit d6a7127 into home-assistant:dev Aug 17, 2023
21 checks passed
@bieniu
Copy link
Member Author

bieniu commented Aug 17, 2023

@edenhaus Thanks, we got a pretty nice refactoring of the code here 😁

@bieniu bieniu deleted the tractive-improve-availability branch August 17, 2023 10:16
@edenhaus edenhaus added this to the 2023.8.3 milestone Aug 17, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
@home-assistant home-assistant unlocked this conversation Aug 18, 2023
@frenck frenck removed this from the 2023.8.3 milestone Aug 18, 2023
@frenck
Copy link
Member

frenck commented Aug 18, 2023

Removed this PR from the milestone, as it causes conflicts and cannot be merged cleanly on the the rc branch for including in a patch release.

../Frenck

@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 2023
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.

Tractive entities are unknown or unavailable after HA start
4 participants