Skip to content

Improve reolink generic typing#88786

Merged
cdce8p merged 4 commits into
home-assistant:devfrom
cdce8p:type-reolink
Mar 6, 2023
Merged

Improve reolink generic typing#88786
cdce8p merged 4 commits into
home-assistant:devfrom
cdce8p:type-reolink

Conversation

@cdce8p
Copy link
Copy Markdown
Member

@cdce8p cdce8p commented Feb 26, 2023

Proposed change

Improve generic typing around CoordinatorEntity and DataUpdateCoordinator.

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

  • 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.
  • 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
Copy Markdown
Contributor

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

Code owner commands

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

Comment on lines -62 to -64
if self.coordinator.data is None:
return None

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the check for new firmware fails, it will raise either a TimeoutError or UpdateFailed. Both will set last_updaate_success = False which in turn will set the available property to False. So this shouldn't be necessary.

async with async_timeout.timeout(host.api.timeout):
try:
return await host.api.check_new_firmware()
except ReolinkError as err:
raise UpdateFailed(
f"Error checking Reolink firmware update {host.api.nvr_name}"
) from err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

True, this can indeed be removed.

Comment on lines -62 to -64
if self.coordinator.data is None:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

True, this can indeed be removed.

Comment thread homeassistant/components/reolink/entity.py
Comment thread homeassistant/components/reolink/entity.py
@starkillerOG
Copy link
Copy Markdown
Contributor

@cdce8p thanks for this PR!

@cdce8p
Copy link
Copy Markdown
Member Author

cdce8p commented Mar 6, 2023

@starkillerOG Would you mind to take a look at this again? I've rebased the PR and added ReolinkDeviceCoordinatorEntity as common base class.

@starkillerOG
Copy link
Copy Markdown
Contributor

@cdce8p Alright I was very confused at first but now I do get it, but the naming is very confusing.
Please rename ReolinkDeviceCoordinatorEntity -> ReolinkHostCoordinatorEntity
and ReolinkCoordinatorEntity -> ReolinkChannelCoordinatorEntity

Please Update the ReolinkHostCoordinatorEntity description to:

    """Parent class for entities that control the Reolink NVR itself, without a channel.
    A camera connected directly to HomeAssistant without using a NVR is in the reolink API
    basically a NVR with a single channel that has the camera connected to that channel.
    """

Also please change the Base Coordinator description accordingly.

Unfortunatly the imports in all platforms will then also have to be updated (sorry).

@cdce8p cdce8p requested a review from starkillerOG March 6, 2023 16:03
Comment thread homeassistant/components/reolink/entity.py Outdated
Copy link
Copy Markdown
Contributor

@starkillerOG starkillerOG 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 to me, appart for one docstring.

Co-authored-by: starkillerOG <starkiller.og@gmail.com>
@cdce8p cdce8p added the smash Indicator this PR is close to finish for merging or closing label Mar 6, 2023
Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @cdce8p 👍

../Frenck

@cdce8p cdce8p merged commit 8403495 into home-assistant:dev Mar 6, 2023
@cdce8p cdce8p deleted the type-reolink branch March 6, 2023 20:54
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed code-quality integration: reolink Quality Scale: No score small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants