-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Updater component is always available and shows on/off depending on whether an update is available or not #25418
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
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
79efbaf
Updater Component is always available and shows on/off wether an upda…
Santobert 008b145
Use == instead of is to compare strings
Santobert 9efcbb7
Edit log message when local version is newer
Santobert c50a515
One more commit to trigger CI
Santobert 842e49f
Merge branch 'dev' into edit_updater_component
Santobert eaf3620
Add binary sensor
Santobert b31bffe
Remove ATTR
Santobert e1df96e
Use dispatcher
Santobert 036101f
Use callback instead of async
Santobert 345cb10
Make flake happy
Santobert bd7f423
Fix callback
Santobert 1aff744
discover binary sensor
Santobert 940f3f8
flake
Santobert 04883d9
Fix discovery
Santobert 3bd8a05
prepared tests, TODO
Santobert cc927da
Fix tests
Santobert 6be42c8
Test release notes
Santobert 92d2a4b
Add one more test
Santobert 3f896a4
Add another test
Santobert 82af5f3
Add docstring
Santobert 5e2bae5
Revert "Add another test"
Santobert 22976d2
Remove unused file
Santobert c63db00
Update docstrings
Santobert 42e3d65
mock time
Santobert fa1b618
Test renaming entity
Santobert 69e7c86
Add test_rename_entity
Santobert 53bec5e
Improve test_rename_entity
Santobert 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Support for Home Assistant Updater binary sensors.""" | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.components.binary_sensor import BinarySensorDevice | ||
| from homeassistant.helpers.dispatcher import async_dispatcher_connect | ||
|
|
||
| from . import ATTR_NEWEST_VERSION, ATTR_RELEASE_NOTES, DISPATCHER_REMOTE_UPDATE, Updater | ||
|
|
||
|
|
||
| async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): | ||
| """Set up the updater binary sensors.""" | ||
| async_add_entities([UpdaterBinary()]) | ||
|
|
||
|
|
||
| class UpdaterBinary(BinarySensorDevice): | ||
| """Representation of an updater binary sensor.""" | ||
|
|
||
| def __init__(self): | ||
| """Initialize the binary sensor.""" | ||
| self._update_available = None | ||
| self._release_notes = None | ||
| self._newest_version = None | ||
| self._unsub_dispatcher = None | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| """Return the name of the binary sensor, if any.""" | ||
| return "Updater" | ||
|
|
||
| @property | ||
| def unique_id(self) -> str: | ||
| """Return a unique ID.""" | ||
| return "updater" | ||
|
|
||
| @property | ||
| def is_on(self) -> bool: | ||
| """Return true if the binary sensor is on.""" | ||
| return self._update_available | ||
|
|
||
| @property | ||
| def available(self) -> bool: | ||
| """Return True if entity is available.""" | ||
| return self._update_available is not None | ||
|
|
||
| @property | ||
| def should_poll(self) -> bool: | ||
| """Return True if entity has to be polled for state.""" | ||
| return False | ||
|
|
||
| @property | ||
| def device_state_attributes(self) -> dict: | ||
| """Return the optional state attributes.""" | ||
| data = super().device_state_attributes | ||
| if data is None: | ||
| data = {} | ||
| if self._release_notes: | ||
| data[ATTR_RELEASE_NOTES] = self._release_notes | ||
| if self._newest_version: | ||
| data[ATTR_NEWEST_VERSION] = self._newest_version | ||
| return data | ||
|
|
||
| async def async_added_to_hass(self): | ||
| """Register update dispatcher.""" | ||
|
|
||
| @callback | ||
| def async_state_update(updater: Updater): | ||
| """Update callback.""" | ||
| self._newest_version = updater.newest_version | ||
| self._release_notes = updater.release_notes | ||
| self._update_available = updater.update_available | ||
| self.async_schedule_update_ha_state() | ||
|
|
||
| self._unsub_dispatcher = async_dispatcher_connect( | ||
| self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update | ||
| ) | ||
|
|
||
| async def async_will_remove_from_hass(self): | ||
| """Register update dispatcher.""" | ||
| if self._unsub_dispatcher is not None: | ||
| self._unsub_dispatcher() | ||
| self._unsub_dispatcher = None |
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.