-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add Reolink update entity #87865
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
Merged
Merged
Add Reolink update entity #87865
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0028aa8
Reolink host firmware update
starkillerOG 7a6e252
styling
starkillerOG 3b9f1b1
fix tests
starkillerOG 58d4752
Move _attr_has_entity_name to the base reolink entity class
starkillerOG 84d7309
use asyncio gather
starkillerOG bb4bb66
move static
starkillerOG de2091f
Update update.py
starkillerOG 0b091fc
Update docstrings
starkillerOG 391e367
add extra docstring explanation
starkillerOG 08eef57
fix styling
starkillerOG 5351665
Merge branch 'dev' into reolink_update
starkillerOG 6ae9192
raise HomeAssistantError instead of ReolinkError
starkillerOG aa846b5
Merge branch 'reolink_update' of https://github.com/starkillerOG/home…
starkillerOG ef6a1d9
fix styling
starkillerOG aca0d70
fix string formatting
starkillerOG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """Update entities for Reolink devices.""" | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from reolink_aio.exceptions import ReolinkError | ||
|
|
||
| from homeassistant.components.update import ( | ||
| UpdateDeviceClass, | ||
| UpdateEntity, | ||
| UpdateEntityFeature, | ||
| ) | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.exceptions import HomeAssistantError | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from . import ReolinkData | ||
| from .const import DOMAIN | ||
| from .entity import ReolinkBaseCoordinatorEntity | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| config_entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set up update entities for Reolink component.""" | ||
| reolink_data: ReolinkData = hass.data[DOMAIN][config_entry.entry_id] | ||
| async_add_entities([ReolinkUpdateEntity(reolink_data)]) | ||
|
|
||
|
|
||
| class ReolinkUpdateEntity(ReolinkBaseCoordinatorEntity, UpdateEntity): | ||
| """Update entity for a Netgear device.""" | ||
|
|
||
| _attr_device_class = UpdateDeviceClass.FIRMWARE | ||
| _attr_supported_features = UpdateEntityFeature.INSTALL | ||
| _attr_release_url = "https://reolink.com/download-center/" | ||
| _attr_name = "Update" | ||
|
|
||
| def __init__( | ||
| self, | ||
| reolink_data: ReolinkData, | ||
| ) -> None: | ||
| """Initialize a Netgear device.""" | ||
| super().__init__(reolink_data, reolink_data.firmware_coordinator) | ||
|
|
||
| self._attr_unique_id = f"{self._host.unique_id}_update" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to add the platform domain to the unique_id. The entity registry is aware of both the integration domain and the platform domain. It's good to add a unique suffix if we're planning to add more than one entity type for the platform. |
||
|
|
||
| @property | ||
| def installed_version(self) -> str | None: | ||
| """Version currently in use.""" | ||
| return self._host.api.sw_version | ||
|
|
||
| @property | ||
| def latest_version(self) -> str | None: | ||
| """Latest version available for install.""" | ||
| if self.coordinator.data is None: | ||
| return None | ||
|
|
||
| if not self.coordinator.data: | ||
| return self.installed_version | ||
|
frenck marked this conversation as resolved.
|
||
|
|
||
| return self.coordinator.data | ||
|
|
||
| async def async_install( | ||
| self, version: str | None, backup: bool, **kwargs: Any | ||
| ) -> None: | ||
| """Install the latest firmware version.""" | ||
| try: | ||
| await self._host.api.update_firmware() | ||
| except ReolinkError as err: | ||
| raise HomeAssistantError( | ||
| f"Error trying to update Reolink firmware: {err}" | ||
| ) from err | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.