mirror of
https://github.com/home-assistant/core
synced 2024-10-01 05:30:36 +02:00
BMW: Remove deprecated refresh from cloud button (#97864)
* Remove deprecated refresh from cloud button * Clean up strings.json
This commit is contained in:
parent
c478a81deb
commit
74d02a1574
@ -26,14 +26,17 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class BMWButtonEntityDescription(ButtonEntityDescription):
|
||||
class BMWRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
remote_function: Callable[[MyBMWVehicle], Coroutine[Any, Any, RemoteServiceStatus]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class BMWButtonEntityDescription(ButtonEntityDescription, BMWRequiredKeysMixin):
|
||||
"""Class describing BMW button entities."""
|
||||
|
||||
enabled_when_read_only: bool = False
|
||||
remote_function: Callable[
|
||||
[MyBMWVehicle], Coroutine[Any, Any, RemoteServiceStatus]
|
||||
] | None = None
|
||||
account_function: Callable[[BMWDataUpdateCoordinator], Coroutine] | None = None
|
||||
is_available: Callable[[MyBMWVehicle], bool] = lambda _: True
|
||||
|
||||
|
||||
@ -69,13 +72,6 @@ BUTTON_TYPES: tuple[BMWButtonEntityDescription, ...] = (
|
||||
icon="mdi:crosshairs-question",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_vehicle_finder(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
key="refresh",
|
||||
translation_key="refresh",
|
||||
icon="mdi:refresh",
|
||||
account_function=lambda coordinator: coordinator.async_request_refresh(),
|
||||
enabled_when_read_only=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@ -120,22 +116,9 @@ class BMWButton(BMWBaseEntity, ButtonEntity):
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Press the button."""
|
||||
if self.entity_description.remote_function:
|
||||
try:
|
||||
await self.entity_description.remote_function(self.vehicle)
|
||||
except MyBMWAPIError as ex:
|
||||
raise HomeAssistantError(ex) from ex
|
||||
elif self.entity_description.account_function:
|
||||
_LOGGER.warning(
|
||||
"The 'Refresh from cloud' button is deprecated. Use the"
|
||||
" 'homeassistant.update_entity' service with any BMW entity for a full"
|
||||
" reload. See"
|
||||
" https://www.home-assistant.io/integrations/bmw_connected_drive/#update-the-state--refresh-from-api"
|
||||
" for details"
|
||||
)
|
||||
try:
|
||||
await self.entity_description.account_function(self.coordinator)
|
||||
except MyBMWAPIError as ex:
|
||||
raise HomeAssistantError(ex) from ex
|
||||
try:
|
||||
await self.entity_description.remote_function(self.vehicle)
|
||||
except MyBMWAPIError as ex:
|
||||
raise HomeAssistantError(ex) from ex
|
||||
|
||||
self.coordinator.async_update_listeners()
|
||||
|
@ -66,9 +66,6 @@
|
||||
},
|
||||
"find_vehicle": {
|
||||
"name": "Find vehicle"
|
||||
},
|
||||
"refresh": {
|
||||
"name": "Refresh from cloud"
|
||||
}
|
||||
},
|
||||
"lock": {
|
||||
|
@ -61,18 +61,6 @@
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
}),
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Data provided by MyBMW',
|
||||
'friendly_name': 'i4 eDrive40 Refresh from cloud',
|
||||
'icon': 'mdi:refresh',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.i4_edrive40_refresh_from_cloud',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
}),
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Data provided by MyBMW',
|
||||
@ -121,17 +109,5 @@
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
}),
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Data provided by MyBMW',
|
||||
'friendly_name': 'i3 (+ REX) Refresh from cloud',
|
||||
'icon': 'mdi:refresh',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.i3_rex_refresh_from_cloud',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
|
@ -1,4 +1,7 @@
|
||||
"""Test BMW buttons."""
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from bimmer_connected.models import MyBMWRemoteServiceError
|
||||
from bimmer_connected.vehicle.remote_services import RemoteServices
|
||||
import pytest
|
||||
import respx
|
||||
@ -8,6 +11,7 @@ from homeassistant.components.bmw_connected_drive.coordinator import (
|
||||
BMWDataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from . import setup_mocked_integration
|
||||
|
||||
@ -58,22 +62,31 @@ async def test_update_triggers_success(
|
||||
assert BMWDataUpdateCoordinator.async_update_listeners.call_count == 1
|
||||
|
||||
|
||||
async def test_refresh_from_cloud(
|
||||
async def test_update_failed(
|
||||
hass: HomeAssistant,
|
||||
bmw_fixture: respx.Router,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test button press for deprecated service."""
|
||||
"""Test button press."""
|
||||
|
||||
# Setup component
|
||||
assert await setup_mocked_integration(hass)
|
||||
BMWDataUpdateCoordinator.async_update_listeners.reset_mock()
|
||||
|
||||
# Test
|
||||
await hass.services.async_call(
|
||||
"button",
|
||||
"press",
|
||||
blocking=True,
|
||||
target={"entity_id": "button.i4_edrive40_refresh_from_cloud"},
|
||||
# Setup exception
|
||||
monkeypatch.setattr(
|
||||
RemoteServices,
|
||||
"trigger_remote_service",
|
||||
AsyncMock(side_effect=MyBMWRemoteServiceError),
|
||||
)
|
||||
assert RemoteServices.trigger_remote_service.call_count == 0
|
||||
assert BMWDataUpdateCoordinator.async_update_listeners.call_count == 2
|
||||
|
||||
# Test
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
"button",
|
||||
"press",
|
||||
blocking=True,
|
||||
target={"entity_id": "button.i4_edrive40_flash_lights"},
|
||||
)
|
||||
assert RemoteServices.trigger_remote_service.call_count == 1
|
||||
assert BMWDataUpdateCoordinator.async_update_listeners.call_count == 0
|
||||
|
Loading…
Reference in New Issue
Block a user