-
-
Notifications
You must be signed in to change notification settings - Fork 38k
Add button to trigger ota firmware update for Shelly devices #58757
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
frenck
merged 29 commits into
home-assistant:dev
from
mib1185:shelly/add-ota-update-service
Nov 26, 2021
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4109772
add ota update services for block devices
mib1185 a0770e9
add ota update services for rpc devices
mib1185 80d6a43
add tests
mib1185 fd83c8f
use get_device_entry_gen()
mib1185 fed8f32
add button entity
mib1185 95be88d
add ota beta channel switch
mib1185 4ae51b7
fix check beta channel for block device
mib1185 fd21def
use constant for beta attribute
mib1185 46089ef
add tests for button and switch
mib1185 f65acd1
improve button tests
mib1185 1fbc64b
remove constant from device specific dict
mib1185 5965ae5
Apply suggestions from code review
mib1185 6dea2c7
correct descriptions
mib1185 1a90bdb
move do_ota_update into trigger_ota_update funct
mib1185 2c89f16
disable _ota_update_pending shen executed
mib1185 f6af585
log warnings, instead of errors
mib1185 05352bd
catch only expected errors
mib1185 5e8c2dd
always create beta channel switch
mib1185 523f8a6
change button icon to mdi:package-up
mib1185 3394626
correct key from fw to fw_id
mib1185 a4e0479
use firmware_version property instead of low level
mib1185 8fd649e
always create beta channel switch also on gen1
mib1185 df702e8
remove service, trigger ota direct in button
mib1185 bbd7e76
remove support for battery powered devices
mib1185 9ea6b15
remove virtual switch
mib1185 e0b34ef
add additional button for beta channel updates
mib1185 e5ce13e
adjust tests
mib1185 8a49e60
disable beta button by default
mib1185 7a597d7
Merge branch 'dev' into shelly/add-ota-update-service
mib1185 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,71 @@ | ||
| """Button for Shelly.""" | ||
| from __future__ import annotations | ||
|
|
||
| from typing import cast | ||
|
|
||
| from homeassistant.components.button import ButtonEntity | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import ENTITY_CATEGORY_CONFIG | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC | ||
| from homeassistant.helpers.entity import DeviceInfo | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
| from homeassistant.util import slugify | ||
|
|
||
| from . import BlockDeviceWrapper, RpcDeviceWrapper | ||
| from .const import BLOCK, CONF_OTA_BETA_CHANNEL, DATA_CONFIG_ENTRY, DOMAIN, RPC | ||
| from .utils import get_block_device_name, get_device_entry_gen, get_rpc_device_name | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| config_entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set buttons for device.""" | ||
| wrapper: RpcDeviceWrapper | BlockDeviceWrapper | None = None | ||
| if get_device_entry_gen(config_entry) == 2: | ||
| if rpc_wrapper := hass.data[DOMAIN][DATA_CONFIG_ENTRY][ | ||
| config_entry.entry_id | ||
| ].get(RPC): | ||
| wrapper = cast(RpcDeviceWrapper, rpc_wrapper) | ||
| else: | ||
| if block_wrapper := hass.data[DOMAIN][DATA_CONFIG_ENTRY][ | ||
| config_entry.entry_id | ||
| ].get(BLOCK): | ||
| wrapper = cast(BlockDeviceWrapper, block_wrapper) | ||
|
|
||
| if wrapper is not None: | ||
| async_add_entities([ShellyOtaUpdateButton(wrapper, config_entry)]) | ||
|
|
||
|
|
||
| class ShellyOtaUpdateButton(ButtonEntity): | ||
| """Defines a Shelly OTA update button.""" | ||
|
|
||
| _attr_icon = "mdi:package-up" | ||
| _attr_entity_category = ENTITY_CATEGORY_CONFIG | ||
|
|
||
| def __init__( | ||
| self, wrapper: RpcDeviceWrapper | BlockDeviceWrapper, entry: ConfigEntry | ||
| ) -> None: | ||
| """Initialize Shelly OTA update button.""" | ||
| self._attr_device_info = DeviceInfo( | ||
| connections={(CONNECTION_NETWORK_MAC, wrapper.mac)} | ||
| ) | ||
|
|
||
| if isinstance(wrapper, RpcDeviceWrapper): | ||
| device_name = get_rpc_device_name(wrapper.device) | ||
| else: | ||
| device_name = get_block_device_name(wrapper.device) | ||
|
|
||
| self._attr_name = f"{device_name} OTA Update" | ||
| self._attr_unique_id = slugify(self._attr_name) | ||
|
|
||
| self.entry = entry | ||
| self.wrapper = wrapper | ||
|
|
||
| async def async_press(self) -> None: | ||
| """Triggers the OTA update service.""" | ||
| await self.wrapper.async_trigger_ota_update( | ||
| beta=bool(self.entry.options.get(CONF_OTA_BETA_CHANNEL)) | ||
| ) | ||
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
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.