From b65d4a9efd65586ae6fb2f85fdd5f286baf8819a Mon Sep 17 00:00:00 2001 From: mkmer Date: Sun, 1 Jan 2023 14:08:54 -0500 Subject: [PATCH] Bump whirlpool-sixth-sense to 0.18.0 (#84945) * bump whirlpool_sixth_sense to 18.0 add callback method initiated in 18.0 * add disconnect to mock --- homeassistant/components/whirlpool/climate.py | 8 +- .../components/whirlpool/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/whirlpool/conftest.py | 1 + tests/components/whirlpool/test_climate.py | 76 +++++++------------ 6 files changed, 36 insertions(+), 55 deletions(-) diff --git a/homeassistant/components/whirlpool/climate.py b/homeassistant/components/whirlpool/climate.py index ad4cd2ea389..0b5fd84dd00 100644 --- a/homeassistant/components/whirlpool/climate.py +++ b/homeassistant/components/whirlpool/climate.py @@ -107,8 +107,8 @@ class AirConEntity(ClimateEntity): def __init__(self, hass, said, name, backend_selector: BackendSelector, auth: Auth): """Initialize the entity.""" - self._aircon = Aircon(backend_selector, auth, said, self.async_write_ha_state) - + self._aircon = Aircon(backend_selector, auth, said) + self._aircon.register_attr_callback(self.async_write_ha_state) self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, said, hass=hass) self._attr_name = name if name is not None else said self._attr_unique_id = said @@ -117,6 +117,10 @@ class AirConEntity(ClimateEntity): """Connect aircon to the cloud.""" await self._aircon.connect() + async def async_will_remove_from_hass(self) -> None: + """Close Whrilpool Appliance sockets before removing.""" + await self._aircon.disconnect() + @property def available(self) -> bool: """Return True if entity is available.""" diff --git a/homeassistant/components/whirlpool/manifest.json b/homeassistant/components/whirlpool/manifest.json index fda9ba651b5..89315a64d85 100644 --- a/homeassistant/components/whirlpool/manifest.json +++ b/homeassistant/components/whirlpool/manifest.json @@ -3,7 +3,7 @@ "name": "Whirlpool Sixth Sense", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/whirlpool", - "requirements": ["whirlpool-sixth-sense==0.17.1"], + "requirements": ["whirlpool-sixth-sense==0.18.0"], "codeowners": ["@abmantis"], "iot_class": "cloud_push", "loggers": ["whirlpool"] diff --git a/requirements_all.txt b/requirements_all.txt index 18b1750caf6..63a022015f5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2570,7 +2570,7 @@ waterfurnace==1.1.0 webexteamssdk==1.1.1 # homeassistant.components.whirlpool -whirlpool-sixth-sense==0.17.1 +whirlpool-sixth-sense==0.18.0 # homeassistant.components.whois whois==0.9.16 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 105681ca70b..cb8ddf571a8 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1795,7 +1795,7 @@ wallbox==0.4.12 watchdog==2.2.0 # homeassistant.components.whirlpool -whirlpool-sixth-sense==0.17.1 +whirlpool-sixth-sense==0.18.0 # homeassistant.components.whois whois==0.9.16 diff --git a/tests/components/whirlpool/conftest.py b/tests/components/whirlpool/conftest.py index a5e044b51ca..faf188c288b 100644 --- a/tests/components/whirlpool/conftest.py +++ b/tests/components/whirlpool/conftest.py @@ -56,6 +56,7 @@ def get_aircon_mock(said): """Get a mock of an air conditioner.""" mock_aircon = mock.Mock(said=said) mock_aircon.connect = AsyncMock() + mock_aircon.disconnect = AsyncMock() mock_aircon.get_online.return_value = True mock_aircon.get_power_on.return_value = True mock_aircon.get_mode.return_value = whirlpool.aircon.Mode.Cool diff --git a/tests/components/whirlpool/test_climate.py b/tests/components/whirlpool/test_climate.py index 26dcd5dbf9f..efbe1076749 100644 --- a/tests/components/whirlpool/test_climate.py +++ b/tests/components/whirlpool/test_climate.py @@ -51,15 +51,13 @@ from . import init_integration async def update_ac_state( hass: HomeAssistant, entity_id: str, - mock_aircon_api_instances: MagicMock, - mock_instance_idx: int, + mock_aircon_api_instance: MagicMock, ): """Simulate an update trigger from the API.""" - update_ha_state_cb = mock_aircon_api_instances.call_args_list[ - mock_instance_idx - ].args[3] - update_ha_state_cb() - await hass.async_block_till_done() + for call in mock_aircon_api_instance.register_attr_callback.call_args_list: + update_ha_state_cb = call[0][0] + update_ha_state_cb() + await hass.async_block_till_done() return hass.states.get(entity_id) @@ -72,7 +70,11 @@ async def test_no_appliances( assert len(hass.states.async_all()) == 0 -async def test_static_attributes(hass: HomeAssistant, mock_aircon1_api: MagicMock): +async def test_static_attributes( + hass: HomeAssistant, + mock_aircon1_api: MagicMock, + mock_aircon_api_instances: MagicMock, +): """Test static climate attributes.""" await init_integration(hass) @@ -137,81 +139,56 @@ async def test_dynamic_attributes( ): entity_id = clim_test_instance.entity_id mock_instance = clim_test_instance.mock_instance - mock_instance_idx = clim_test_instance.mock_instance_idx state = hass.states.get(entity_id) assert state is not None assert state.state == HVACMode.COOL mock_instance.get_power_on.return_value = False - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.state == HVACMode.OFF mock_instance.get_online.return_value = False - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.state == STATE_UNAVAILABLE mock_instance.get_power_on.return_value = True mock_instance.get_online.return_value = True - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.state == HVACMode.COOL mock_instance.get_mode.return_value = whirlpool.aircon.Mode.Heat - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.state == HVACMode.HEAT mock_instance.get_mode.return_value = whirlpool.aircon.Mode.Fan - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.state == HVACMode.FAN_ONLY mock_instance.get_fanspeed.return_value = whirlpool.aircon.FanSpeed.Auto - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.attributes[ATTR_FAN_MODE] == HVACMode.AUTO mock_instance.get_fanspeed.return_value = whirlpool.aircon.FanSpeed.Low - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.attributes[ATTR_FAN_MODE] == FAN_LOW mock_instance.get_fanspeed.return_value = whirlpool.aircon.FanSpeed.Medium - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.attributes[ATTR_FAN_MODE] == FAN_MEDIUM mock_instance.get_fanspeed.return_value = whirlpool.aircon.FanSpeed.High - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.attributes[ATTR_FAN_MODE] == FAN_HIGH mock_instance.get_fanspeed.return_value = whirlpool.aircon.FanSpeed.Off - state = await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) + state = await update_ac_state(hass, entity_id, mock_instance) assert state.attributes[ATTR_FAN_MODE] == FAN_OFF mock_instance.get_current_temp.return_value = 15 mock_instance.get_temp.return_value = 20 mock_instance.get_current_humidity.return_value = 80 mock_instance.get_h_louver_swing.return_value = True - attributes = ( - await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) - ).attributes + attributes = (await update_ac_state(hass, entity_id, mock_instance)).attributes assert attributes[ATTR_CURRENT_TEMPERATURE] == 15 assert attributes[ATTR_TEMPERATURE] == 20 assert attributes[ATTR_CURRENT_HUMIDITY] == 80 @@ -221,11 +198,7 @@ async def test_dynamic_attributes( mock_instance.get_temp.return_value = 21 mock_instance.get_current_humidity.return_value = 70 mock_instance.get_h_louver_swing.return_value = False - attributes = ( - await update_ac_state( - hass, entity_id, mock_aircon_api_instances, mock_instance_idx - ) - ).attributes + attributes = (await update_ac_state(hass, entity_id, mock_instance)).attributes assert attributes[ATTR_CURRENT_TEMPERATURE] == 16 assert attributes[ATTR_TEMPERATURE] == 21 assert attributes[ATTR_CURRENT_HUMIDITY] == 70 @@ -233,7 +206,10 @@ async def test_dynamic_attributes( async def test_service_calls( - hass: HomeAssistant, mock_aircon1_api: MagicMock, mock_aircon2_api: MagicMock + hass: HomeAssistant, + mock_aircon_api_instances: MagicMock, + mock_aircon1_api: MagicMock, + mock_aircon2_api: MagicMock, ): """Test controlling the entity through service calls.""" await init_integration(hass)