-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Add update entity platform #68248
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 update entity platform #68248
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81452fc
Add update entity platform
frenck c45675e
Add demo
frenck 2b6b0f2
Default entity category to CONFIG
frenck fa8806d
Wording
frenck c50adda
Handle install failures more robust
frenck 199a49c
Fix update progress demo
frenck 7bf56b6
Make install support optional
frenck 465d52d
Always reset progress when install finishes/aborts/fails/succeeds
frenck 17a888a
Improve skipped version handling
frenck 724ff1d
Process review comments
frenck ac28425
Process review comments
frenck 7d3fc06
Process review comments
frenck 4aac3de
Use IntEnum for available features
frenck 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| "sensor", | ||
| "siren", | ||
| "switch", | ||
| "update", | ||
| "vacuum", | ||
| "water_heater", | ||
| ] | ||
|
|
||
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,147 @@ | ||
| """Demo platform that offers fake update entities.""" | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
|
|
||
| from homeassistant.components.update import UpdateDeviceClass, UpdateEntity | ||
| from homeassistant.components.update.const import ( | ||
| SUPPORT_BACKUP, | ||
| SUPPORT_INSTALL, | ||
| SUPPORT_PROGRESS, | ||
| SUPPORT_SPECIFIC_VERSION, | ||
| ) | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import DEVICE_DEFAULT_NAME | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity import DeviceInfo | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
| from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType | ||
|
|
||
| from . import DOMAIN | ||
|
|
||
|
|
||
| async def async_setup_platform( | ||
| hass: HomeAssistant, | ||
| config: ConfigType, | ||
| async_add_entities: AddEntitiesCallback, | ||
| discovery_info: DiscoveryInfoType | None = None, | ||
| ) -> None: | ||
| """Set up demo update entities.""" | ||
| async_add_entities( | ||
| [ | ||
| DemoUpdate( | ||
| unique_id="update_no_install", | ||
| name="Demo Update No Install", | ||
| title="Awesomesoft Inc.", | ||
| current_version="1.0.0", | ||
| latest_version="1.0.1", | ||
| release_summary="Awesome update, fixing everything!", | ||
| release_url="https://www.example.com/release/1.0.1", | ||
| support_install=False, | ||
| ), | ||
| DemoUpdate( | ||
| unique_id="update_2_date", | ||
| name="Demo No Update", | ||
| title="AdGuard Home", | ||
| current_version="1.0.0", | ||
| latest_version="1.0.0", | ||
| ), | ||
| DemoUpdate( | ||
| unique_id="update_addon", | ||
| name="Demo add-on", | ||
| title="AdGuard Home", | ||
| current_version="1.0.0", | ||
| latest_version="1.0.1", | ||
| release_summary="Awesome update, fixing everything!", | ||
| release_url="https://www.example.com/release/1.0.1", | ||
| ), | ||
| DemoUpdate( | ||
| unique_id="update_light_bulb", | ||
| name="Demo Living Room Bulb Update", | ||
| title="Philips Lamps Firmware", | ||
| current_version="1.93.3", | ||
| latest_version="1.94.2", | ||
| release_summary="Added support for effects", | ||
| release_url="https://www.example.com/release/1.93.3", | ||
| device_class=UpdateDeviceClass.FIRMWARE, | ||
| ), | ||
| DemoUpdate( | ||
| unique_id="update_support_progress", | ||
| name="Demo Update with Progress", | ||
| title="Philips Lamps Firmware", | ||
| current_version="1.93.3", | ||
| latest_version="1.94.2", | ||
| support_progress=True, | ||
| release_summary="Added support for effects", | ||
| release_url="https://www.example.com/release/1.93.3", | ||
| device_class=UpdateDeviceClass.FIRMWARE, | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| config_entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set up the Demo config entry.""" | ||
| await async_setup_platform(hass, {}, async_add_entities) | ||
|
|
||
|
|
||
| class DemoUpdate(UpdateEntity): | ||
| """Representation of a demo update entity.""" | ||
|
|
||
| _attr_should_poll = False | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| unique_id: str, | ||
| name: str, | ||
| title: str | None, | ||
| current_version: str | None, | ||
| latest_version: str | None, | ||
| release_summary: str | None = None, | ||
| release_url: str | None = None, | ||
| support_progress: bool = False, | ||
| support_install: bool = True, | ||
| device_class: UpdateDeviceClass | None = None, | ||
| ) -> None: | ||
| """Initialize the Demo select entity.""" | ||
| self._attr_current_version = current_version | ||
| self._attr_device_class = device_class | ||
| self._attr_latest_version = latest_version | ||
| self._attr_name = name or DEVICE_DEFAULT_NAME | ||
| self._attr_release_summary = release_summary | ||
| self._attr_release_url = release_url | ||
| self._attr_title = title | ||
| self._attr_unique_id = unique_id | ||
| self._attr_device_info = DeviceInfo( | ||
| identifiers={(DOMAIN, unique_id)}, | ||
| name=name, | ||
| ) | ||
| if support_install: | ||
| self._attr_supported_features |= ( | ||
| SUPPORT_INSTALL | SUPPORT_BACKUP | SUPPORT_SPECIFIC_VERSION | ||
| ) | ||
| if support_progress: | ||
| self._attr_supported_features |= SUPPORT_PROGRESS | ||
|
|
||
| async def async_install( | ||
| self, | ||
| version: str | None = None, | ||
| backup: bool | None = None, | ||
| ) -> None: | ||
| """Install an update.""" | ||
| if self.supported_features & SUPPORT_PROGRESS: | ||
| for progress in range(0, 100, 10): | ||
| self._attr_in_progress = progress | ||
| await self.async_update_ha_state() | ||
| await asyncio.sleep(0.5) | ||
|
|
||
| self._attr_in_progress = False | ||
| self._attr_current_version = ( | ||
| version if version is not None else self.latest_version | ||
| ) | ||
| await self.async_update_ha_state() | ||
|
frenck marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
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.