From d2e6b863b7776fbe4c88715e278cd05abf0eeff9 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 3 Jun 2020 02:29:49 +0200 Subject: [PATCH] Upgrade wled 0.4.1 (#36091) --- homeassistant/components/wled/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/wled/__init__.py | 12 ++++++++---- tests/components/wled/test_config_flow.py | 14 ++++++++++---- tests/components/wled/test_init.py | 8 ++++---- tests/components/wled/test_light.py | 11 ++++++----- tests/components/wled/test_switch.py | 9 +++++---- 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/wled/manifest.json b/homeassistant/components/wled/manifest.json index 0e5bb990bae..aa3f944ed1e 100644 --- a/homeassistant/components/wled/manifest.json +++ b/homeassistant/components/wled/manifest.json @@ -3,7 +3,7 @@ "name": "WLED", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/wled", - "requirements": ["wled==0.3.0"], + "requirements": ["wled==0.4.1"], "zeroconf": ["_wled._tcp.local."], "codeowners": ["@frenck"], "quality_scale": "platinum" diff --git a/requirements_all.txt b/requirements_all.txt index b18b2048b11..a835730dbae 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2195,7 +2195,7 @@ wirelesstagpy==0.4.0 withings-api==2.1.3 # homeassistant.components.wled -wled==0.3.0 +wled==0.4.1 # homeassistant.components.xbee xbee-helper==0.0.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 12e90ae36f1..1287a65fcdd 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -898,7 +898,7 @@ wiffi==1.0.0 withings-api==2.1.3 # homeassistant.components.wled -wled==0.3.0 +wled==0.4.1 # homeassistant.components.bluesound # homeassistant.components.rest diff --git a/tests/components/wled/__init__.py b/tests/components/wled/__init__.py index f6bd0643450..487ccd9ab9e 100644 --- a/tests/components/wled/__init__.py +++ b/tests/components/wled/__init__.py @@ -1,5 +1,7 @@ """Tests for the WLED integration.""" +import json + from homeassistant.components.wled.const import DOMAIN from homeassistant.const import CONF_HOST, CONF_MAC from homeassistant.core import HomeAssistant @@ -17,27 +19,29 @@ async def init_integration( """Set up the WLED integration in Home Assistant.""" fixture = "wled/rgb.json" if not rgbw else "wled/rgbw.json" + data = json.loads(load_fixture(fixture)) + aioclient_mock.get( "http://192.168.1.123:80/json/", - text=load_fixture(fixture), + json=data, headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "http://192.168.1.123:80/json/state", - json={}, + json=data["state"], headers={"Content-Type": "application/json"}, ) aioclient_mock.get( "http://192.168.1.123:80/json/info", - json={}, + json=data["info"], headers={"Content-Type": "application/json"}, ) aioclient_mock.get( "http://192.168.1.123:80/json/state", - json={}, + json=data["state"], headers={"Content-Type": "application/json"}, ) diff --git a/tests/components/wled/test_config_flow.py b/tests/components/wled/test_config_flow.py index 6de14a024d4..f5f1ec3099c 100644 --- a/tests/components/wled/test_config_flow.py +++ b/tests/components/wled/test_config_flow.py @@ -1,5 +1,6 @@ """Tests for the WLED config flow.""" import aiohttp +from wled import WLEDConnectionError from homeassistant import data_entry_flow from homeassistant.components.wled import config_flow @@ -9,6 +10,7 @@ from homeassistant.core import HomeAssistant from . import init_integration +from tests.async_mock import MagicMock, patch from tests.common import load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -59,8 +61,9 @@ async def test_show_zerconf_form( assert result["type"] == data_entry_flow.RESULT_TYPE_FORM +@patch("homeassistant.components.wled.WLED.update", side_effect=WLEDConnectionError) async def test_connection_error( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + update_mock: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we show user form on WLED connection error.""" aioclient_mock.get("http://example.com/json/", exc=aiohttp.ClientError) @@ -76,8 +79,9 @@ async def test_connection_error( assert result["type"] == data_entry_flow.RESULT_TYPE_FORM +@patch("homeassistant.components.wled.WLED.update", side_effect=WLEDConnectionError) async def test_zeroconf_connection_error( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + update_mock: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we abort zeroconf flow on WLED connection error.""" aioclient_mock.get("http://192.168.1.123/json/", exc=aiohttp.ClientError) @@ -92,8 +96,9 @@ async def test_zeroconf_connection_error( assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT +@patch("homeassistant.components.wled.WLED.update", side_effect=WLEDConnectionError) async def test_zeroconf_confirm_connection_error( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + update_mock: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we abort zeroconf flow on WLED connection error.""" aioclient_mock.get("http://192.168.1.123:80/json/", exc=aiohttp.ClientError) @@ -112,8 +117,9 @@ async def test_zeroconf_confirm_connection_error( assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT +@patch("homeassistant.components.wled.WLED.update", side_effect=WLEDConnectionError) async def test_zeroconf_no_data( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + update_mock: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we abort if zeroconf provides no data.""" flow = config_flow.WLEDFlowHandler() diff --git a/tests/components/wled/test_init.py b/tests/components/wled/test_init.py index 053c5ebaca0..8ed043530ae 100644 --- a/tests/components/wled/test_init.py +++ b/tests/components/wled/test_init.py @@ -1,20 +1,20 @@ """Tests for the WLED integration.""" -import aiohttp +from wled import WLEDConnectionError from homeassistant.components.wled.const import DOMAIN from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY from homeassistant.core import HomeAssistant +from tests.async_mock import MagicMock, patch from tests.components.wled import init_integration from tests.test_util.aiohttp import AiohttpClientMocker +@patch("homeassistant.components.wled.WLED.update", side_effect=WLEDConnectionError) async def test_config_entry_not_ready( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + mock_update: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test the WLED configuration entry not ready.""" - aioclient_mock.get("http://192.168.1.123:80/json/", exc=aiohttp.ClientError) - entry = await init_integration(hass, aioclient_mock) assert entry.state == ENTRY_STATE_SETUP_RETRY diff --git a/tests/components/wled/test_light.py b/tests/components/wled/test_light.py index f2cc5514a2e..307f1e56411 100644 --- a/tests/components/wled/test_light.py +++ b/tests/components/wled/test_light.py @@ -1,5 +1,5 @@ """Tests for the WLED light platform.""" -import aiohttp +from wled import WLEDConnectionError from homeassistant.components.light import ( ATTR_BRIGHTNESS, @@ -144,7 +144,7 @@ async def test_light_error( aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400) await init_integration(hass, aioclient_mock) - with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"): + with patch("homeassistant.components.wled.WLED.update"): await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, @@ -162,10 +162,11 @@ async def test_light_connection_error( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test error handling of the WLED switches.""" - aioclient_mock.post("http://192.168.1.123:80/json/state", exc=aiohttp.ClientError) await init_integration(hass, aioclient_mock) - with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"): + with patch("homeassistant.components.wled.WLED.update"), patch( + "homeassistant.components.wled.WLED.light", side_effect=WLEDConnectionError + ): await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, @@ -342,7 +343,7 @@ async def test_effect_service_error( aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400) await init_integration(hass, aioclient_mock) - with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"): + with patch("homeassistant.components.wled.WLED.update"): await hass.services.async_call( DOMAIN, SERVICE_EFFECT, diff --git a/tests/components/wled/test_switch.py b/tests/components/wled/test_switch.py index 7d411984cff..388e3317b39 100644 --- a/tests/components/wled/test_switch.py +++ b/tests/components/wled/test_switch.py @@ -1,5 +1,5 @@ """Tests for the WLED switch platform.""" -import aiohttp +from wled import WLEDConnectionError from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.components.wled.const import ( @@ -142,7 +142,7 @@ async def test_switch_error( aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400) await init_integration(hass, aioclient_mock) - with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"): + with patch("homeassistant.components.wled.WLED.update"): await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON, @@ -160,10 +160,11 @@ async def test_switch_connection_error( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test error handling of the WLED switches.""" - aioclient_mock.post("http://192.168.1.123:80/json/state", exc=aiohttp.ClientError) await init_integration(hass, aioclient_mock) - with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"): + with patch("homeassistant.components.wled.WLED.update"), patch( + "homeassistant.components.wled.WLED.nightlight", side_effect=WLEDConnectionError + ): await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON,