From a596acafebb9ff0f9ac637870864e6f4f50742dd Mon Sep 17 00:00:00 2001 From: daxingplay Date: Sat, 30 Mar 2024 14:33:31 +0000 Subject: [PATCH] :bug: unable to enable heating --- .vscode/settings.json | 7 +++++- custom_components/vaillant_plus/client.py | 4 ++-- custom_components/vaillant_plus/climate.py | 22 +++++++++---------- custom_components/vaillant_plus/entity.py | 4 +++- custom_components/vaillant_plus/manifest.json | 4 ++-- tests/test_cliamte.py | 22 +++++++++---------- tests/test_client.py | 4 ++-- tests/test_water_heater.py | 21 ++++++++---------- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a3d535d..aea87d4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,10 @@ "python.pythonPath": "/usr/local/bin/python", "files.associations": { "*.yaml": "home-assistant" - } + }, + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true } \ No newline at end of file diff --git a/custom_components/vaillant_plus/client.py b/custom_components/vaillant_plus/client.py index 5674a75..5f09377 100644 --- a/custom_components/vaillant_plus/client.py +++ b/custom_components/vaillant_plus/client.py @@ -126,12 +126,12 @@ async def close(self) -> None: pass self._state = "CLOSED" - async def control_device(self, attr, value) -> bool: + async def control_device(self, attrs: dict[str, Any]) -> bool: """Send command to control device.""" retry_times = 0 while retry_times < 3: try: - await self._api_client.control_device(self._device_id, attr, value) + await self._api_client.control_device(self._device_id, attrs) return True except InvalidAuthError: await self._get_token() diff --git a/custom_components/vaillant_plus/climate.py b/custom_components/vaillant_plus/climate.py index 60a6a58..34da607 100644 --- a/custom_components/vaillant_plus/climate.py +++ b/custom_components/vaillant_plus/climate.py @@ -169,15 +169,14 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: _LOGGER.debug("Setting HVAC mode to: %s", hvac_mode) if hvac_mode == HVACMode.OFF: - await self._client.control_device( - "Heating_Enable", - 0, - ) + await self._client.control_device({ + "Heating_Enable": False, + }) elif hvac_mode == HVACMode.HEAT: - await self._client.control_device( - "Heating_Enable", - 1, - ) + await self._client.control_device({ + "Heating_Enable": True, + "Mode_Setting_CH": "Cruising", + }) async def async_set_preset_mode(self, preset_mode: str) -> None: """Select new HVAC preset mode.""" @@ -195,7 +194,6 @@ async def async_set_temperature(self, **kwargs) -> None: _LOGGER.debug("Setting target temperature to: %s", new_temperature) - await self._client.control_device( - "Room_Temperature_Setpoint_Comfort", - new_temperature, - ) + await self._client.control_device({ + "Room_Temperature_Setpoint_Comfort": new_temperature, + }) diff --git a/custom_components/vaillant_plus/entity.py b/custom_components/vaillant_plus/entity.py index 42a0b20..0e6b1f3 100644 --- a/custom_components/vaillant_plus/entity.py +++ b/custom_components/vaillant_plus/entity.py @@ -81,4 +81,6 @@ def update_from_latest_data(self, data: dict[str, Any]) -> None: async def send_command(self, attr: str, value: Any) -> None: """Send operations to cloud.""" - await self._client.control_device(attr, value) + await self._client.control_device({ + f"{attr}": value + }) diff --git a/custom_components/vaillant_plus/manifest.json b/custom_components/vaillant_plus/manifest.json index c1cba37..cc100f5 100644 --- a/custom_components/vaillant_plus/manifest.json +++ b/custom_components/vaillant_plus/manifest.json @@ -14,9 +14,9 @@ "vaillant_plus_cn_api" ], "requirements": [ - "vaillant-plus-cn-api==1.2.9" + "vaillant-plus-cn-api==2.0.0" ], "ssdp": [], - "version": "1.2.2", + "version": "1.2.3", "zeroconf": [] } \ No newline at end of file diff --git a/tests/test_cliamte.py b/tests/test_cliamte.py index 3d0d7c9..c37837a 100644 --- a/tests/test_cliamte.py +++ b/tests/test_cliamte.py @@ -36,19 +36,17 @@ async def test_climate_actions(hass, device_api_client): assert climate.preset_mode == PRESET_COMFORT await climate.async_set_temperature(temperature=30) - send_command_func.assert_awaited_with( - "Room_Temperature_Setpoint_Comfort", - 30, - ) + send_command_func.assert_awaited_with({ + "Room_Temperature_Setpoint_Comfort": 30, + }) await climate.async_set_hvac_mode(HVACMode.OFF) - send_command_func.assert_awaited_with( - "Heating_Enable", - 0, - ) + send_command_func.assert_awaited_with({ + "Heating_Enable": False + }) await climate.async_set_hvac_mode(HVACMode.HEAT) - send_command_func.assert_awaited_with( - "Heating_Enable", - 1, - ) + send_command_func.assert_awaited_with({ + "Heating_Enable": True, + "Mode_Setting_CH": "Cruising", + }) diff --git a/tests/test_client.py b/tests/test_client.py index 95e226b..75efaf7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -108,7 +108,7 @@ async def test_client_control_device_invalid_auth( caplog.clear() caplog.set_level(logging.WARNING) - ret = await client.control_device("Test_Attr", "1") + ret = await client.control_device({"Test_Attr": "1"}) messages = [ x.message for x in caplog.records if x.message.startswith("Control device failed") @@ -127,7 +127,7 @@ async def test_client_control_device( caplog.clear() caplog.set_level(logging.WARNING) - ret = await client.control_device("Test_Attr", "1") + ret = await client.control_device({"Test_Attr": "1"}) messages = [ x.message for x in caplog.records if x.message.startswith("Control device failed") diff --git a/tests/test_water_heater.py b/tests/test_water_heater.py index 41970c2..26b02b8 100644 --- a/tests/test_water_heater.py +++ b/tests/test_water_heater.py @@ -23,19 +23,16 @@ async def test_water_heater_actions(hass, device_api_client): send_command_func.assert_not_awaited() await water_heater.async_set_operation_mode(WATER_HEATER_OFF) - send_command_func.assert_awaited_with( - "WarmStar_Tank_Loading_Enable", - 0, - ) + send_command_func.assert_awaited_with({ + "WarmStar_Tank_Loading_Enable": 0, + }) await water_heater.async_set_operation_mode(WATER_HEATER_ON) - send_command_func.assert_awaited_with( - "WarmStar_Tank_Loading_Enable", - 1, - ) + send_command_func.assert_awaited_with({ + "WarmStar_Tank_Loading_Enable": 1, + }) await water_heater.async_set_temperature(temperature=30) - send_command_func.assert_awaited_with( - "DHW_setpoint", - 30, - ) + send_command_func.assert_awaited_with({ + "DHW_setpoint": 30, + })