diff --git a/homeassistant/components/wled/button.py b/homeassistant/components/wled/button.py index 2967067ef44..97877053163 100644 --- a/homeassistant/components/wled/button.py +++ b/homeassistant/components/wled/button.py @@ -7,7 +7,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import DOMAIN, LOGGER +from .const import DOMAIN from .coordinator import WLEDDataUpdateCoordinator from .helpers import wled_exception_handler from .models import WLEDEntity @@ -20,12 +20,7 @@ async def async_setup_entry( ) -> None: """Set up WLED button based on a config entry.""" coordinator: WLEDDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities( - [ - WLEDRestartButton(coordinator), - WLEDUpdateButton(coordinator), - ] - ) + async_add_entities([WLEDRestartButton(coordinator)]) class WLEDRestartButton(WLEDEntity, ButtonEntity): @@ -44,67 +39,3 @@ class WLEDRestartButton(WLEDEntity, ButtonEntity): async def async_press(self) -> None: """Send out a restart command.""" await self.coordinator.wled.reset() - - -class WLEDUpdateButton(WLEDEntity, ButtonEntity): - """Defines a WLED update button.""" - - _attr_device_class = ButtonDeviceClass.UPDATE - _attr_entity_category = EntityCategory.CONFIG - - # Disabled by default, as this entity is deprecated. - _attr_entity_registry_enabled_default = False - - def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: - """Initialize the button entity.""" - super().__init__(coordinator=coordinator) - self._attr_name = f"{coordinator.data.info.name} Update" - self._attr_unique_id = f"{coordinator.data.info.mac_address}_update" - - @property - def available(self) -> bool: - """Return if the entity and an update is available.""" - current = self.coordinator.data.info.version - beta = self.coordinator.data.info.version_latest_beta - stable = self.coordinator.data.info.version_latest_stable - - # If we already run a pre-release, allow upgrading to a newer - # pre-release offer a normal upgrade otherwise. - return ( - super().available - and current is not None - and ( - (stable is not None and stable > current) - or ( - beta is not None - and (current.alpha or current.beta or current.release_candidate) - and beta > current - ) - ) - ) - - @wled_exception_handler - async def async_press(self) -> None: - """Send out a update command.""" - LOGGER.warning( - "The WLED update button '%s' is deprecated, please " - "use the new update entity as a replacement", - self.entity_id, - ) - current = self.coordinator.data.info.version - beta = self.coordinator.data.info.version_latest_beta - stable = self.coordinator.data.info.version_latest_stable - - # If we already run a pre-release, allow update to a newer - # pre-release or newer stable, otherwise, offer a normal stable updates. - version = stable - if ( - current is not None - and beta is not None - and (current.alpha or current.beta or current.release_candidate) - and beta > current - and beta > stable - ): - version = beta - - await self.coordinator.wled.upgrade(version=str(version)) diff --git a/tests/components/wled/test_button.py b/tests/components/wled/test_button.py index a09c7e2aaa3..3cfa4f762ad 100644 --- a/tests/components/wled/test_button.py +++ b/tests/components/wled/test_button.py @@ -1,5 +1,5 @@ """Tests for the WLED button platform.""" -from unittest.mock import AsyncMock, MagicMock +from unittest.mock import MagicMock from freezegun import freeze_time import pytest @@ -95,128 +95,3 @@ async def test_button_connection_error( assert state assert state.state == STATE_UNAVAILABLE assert "Error communicating with API" in caplog.text - - -async def test_button_update_stay_stable( - hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, - init_integration: MockConfigEntry, - mock_wled: MagicMock, - caplog: pytest.LogCaptureFixture, -) -> None: - """Test the update button. - - There is both an update for beta and stable available, however, the device - is currently running a stable version. Therefore, the update button should - update the the next stable (even though beta is newer). - """ - entity_registry = er.async_get(hass) - - entry = entity_registry.async_get("button.wled_rgb_light_update") - assert entry - assert entry.unique_id == "aabbccddeeff_update" - assert entry.entity_category is EntityCategory.CONFIG - - state = hass.states.get("button.wled_rgb_light_update") - assert state - assert state.state == STATE_UNKNOWN - assert state.attributes[ATTR_DEVICE_CLASS] == ButtonDeviceClass.UPDATE - - await hass.services.async_call( - BUTTON_DOMAIN, - SERVICE_PRESS, - {ATTR_ENTITY_ID: "button.wled_rgb_light_update"}, - blocking=True, - ) - await hass.async_block_till_done() - assert mock_wled.upgrade.call_count == 1 - mock_wled.upgrade.assert_called_with(version="0.12.0") - assert ( - "The WLED update button 'button.wled_rgb_light_update' is deprecated" - in caplog.text - ) - - -@pytest.mark.parametrize("mock_wled", ["wled/rgbw.json"], indirect=True) -async def test_button_update_beta_to_stable( - hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, - init_integration: MockConfigEntry, - mock_wled: MagicMock, - caplog: pytest.LogCaptureFixture, -) -> None: - """Test the update button. - - There is both an update for beta and stable available the device - is currently a beta, however, a newer stable is available. Therefore, the - update button should update to the next stable. - """ - await hass.services.async_call( - BUTTON_DOMAIN, - SERVICE_PRESS, - {ATTR_ENTITY_ID: "button.wled_rgbw_light_update"}, - blocking=True, - ) - await hass.async_block_till_done() - assert mock_wled.upgrade.call_count == 1 - mock_wled.upgrade.assert_called_with(version="0.8.6") - assert ( - "The WLED update button 'button.wled_rgbw_light_update' is deprecated" - in caplog.text - ) - - -@pytest.mark.parametrize("mock_wled", ["wled/rgb_single_segment.json"], indirect=True) -async def test_button_update_stay_beta( - hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, - init_integration: MockConfigEntry, - mock_wled: MagicMock, - caplog: pytest.LogCaptureFixture, -) -> None: - """Test the update button. - - There is an update for beta and the device is currently a beta. Therefore, - the update button should update to the next beta. - """ - await hass.services.async_call( - BUTTON_DOMAIN, - SERVICE_PRESS, - {ATTR_ENTITY_ID: "button.wled_rgb_light_update"}, - blocking=True, - ) - await hass.async_block_till_done() - assert mock_wled.upgrade.call_count == 1 - mock_wled.upgrade.assert_called_with(version="0.8.6b2") - assert ( - "The WLED update button 'button.wled_rgb_light_update' is deprecated" - in caplog.text - ) - - -@pytest.mark.parametrize("mock_wled", ["wled/rgb_websocket.json"], indirect=True) -async def test_button_no_update_available( - hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, - init_integration: MockConfigEntry, - mock_wled: MagicMock, -) -> None: - """Test the update button. There is no update available.""" - state = hass.states.get("button.wled_websocket_update") - assert state - assert state.state == STATE_UNAVAILABLE - - -async def test_disabled_by_default( - hass: HomeAssistant, init_integration: MockConfigEntry -) -> None: - """Test that the update button is disabled by default.""" - registry = er.async_get(hass) - - state = hass.states.get("button.wled_rgb_light_update") - assert state is None - - entry = registry.async_get("button.wled_rgb_light_update") - assert entry - assert entry.disabled - assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION