Add support for ESPHome update entities to be checked on demand (#123161)
This commit is contained in:
parent
21da79a249
commit
164cfa85da
5 changed files with 26 additions and 5 deletions
|
@ -17,7 +17,7 @@
|
||||||
"mqtt": ["esphome/discover/#"],
|
"mqtt": ["esphome/discover/#"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"aioesphomeapi==24.6.2",
|
"aioesphomeapi==25.0.0",
|
||||||
"esphome-dashboard-api==1.2.3",
|
"esphome-dashboard-api==1.2.3",
|
||||||
"bleak-esphome==1.0.0"
|
"bleak-esphome==1.0.0"
|
||||||
],
|
],
|
||||||
|
|
|
@ -8,6 +8,7 @@ from typing import Any
|
||||||
from aioesphomeapi import (
|
from aioesphomeapi import (
|
||||||
DeviceInfo as ESPHomeDeviceInfo,
|
DeviceInfo as ESPHomeDeviceInfo,
|
||||||
EntityInfo,
|
EntityInfo,
|
||||||
|
UpdateCommand,
|
||||||
UpdateInfo,
|
UpdateInfo,
|
||||||
UpdateState,
|
UpdateState,
|
||||||
)
|
)
|
||||||
|
@ -259,9 +260,15 @@ class ESPHomeUpdateEntity(EsphomeEntity[UpdateInfo, UpdateState], UpdateEntity):
|
||||||
"""Return the title of the update."""
|
"""Return the title of the update."""
|
||||||
return self._state.title
|
return self._state.title
|
||||||
|
|
||||||
|
@convert_api_error_ha_error
|
||||||
|
async def async_update(self) -> None:
|
||||||
|
"""Command device to check for update."""
|
||||||
|
if self.available:
|
||||||
|
self._client.update_command(key=self._key, command=UpdateCommand.CHECK)
|
||||||
|
|
||||||
@convert_api_error_ha_error
|
@convert_api_error_ha_error
|
||||||
async def async_install(
|
async def async_install(
|
||||||
self, version: str | None, backup: bool, **kwargs: Any
|
self, version: str | None, backup: bool, **kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update the current value."""
|
"""Command device to install update."""
|
||||||
self._client.update_command(key=self._key, install=True)
|
self._client.update_command(key=self._key, command=UpdateCommand.INSTALL)
|
||||||
|
|
|
@ -237,7 +237,7 @@ aioelectricitymaps==0.4.0
|
||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==24.6.2
|
aioesphomeapi==25.0.0
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==2021.11.0
|
aioflo==2021.11.0
|
||||||
|
|
|
@ -225,7 +225,7 @@ aioelectricitymaps==0.4.0
|
||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==24.6.2
|
aioesphomeapi==25.0.0
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==2021.11.0
|
aioflo==2021.11.0
|
||||||
|
|
|
@ -8,6 +8,7 @@ from aioesphomeapi import (
|
||||||
APIClient,
|
APIClient,
|
||||||
EntityInfo,
|
EntityInfo,
|
||||||
EntityState,
|
EntityState,
|
||||||
|
UpdateCommand,
|
||||||
UpdateInfo,
|
UpdateInfo,
|
||||||
UpdateState,
|
UpdateState,
|
||||||
UserService,
|
UserService,
|
||||||
|
@ -15,6 +16,10 @@ from aioesphomeapi import (
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.esphome.dashboard import async_get_dashboard
|
from homeassistant.components.esphome.dashboard import async_get_dashboard
|
||||||
|
from homeassistant.components.homeassistant import (
|
||||||
|
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||||
|
SERVICE_UPDATE_ENTITY,
|
||||||
|
)
|
||||||
from homeassistant.components.update import (
|
from homeassistant.components.update import (
|
||||||
DOMAIN as UPDATE_DOMAIN,
|
DOMAIN as UPDATE_DOMAIN,
|
||||||
SERVICE_INSTALL,
|
SERVICE_INSTALL,
|
||||||
|
@ -527,3 +532,12 @@ async def test_generic_device_update_entity_has_update(
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["in_progress"] == 50
|
assert state.attributes["in_progress"] == 50
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
HOMEASSISTANT_DOMAIN,
|
||||||
|
SERVICE_UPDATE_ENTITY,
|
||||||
|
{ATTR_ENTITY_ID: "update.test_myupdate"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_client.update_command.assert_called_with(key=1, command=UpdateCommand.CHECK)
|
||||||
|
|
Loading…
Add table
Reference in a new issue