From 00f09fb92a498a54a432c15dc4db9626997ba037 Mon Sep 17 00:00:00 2001 From: William Murphy Date: Fri, 29 Mar 2024 18:25:51 +0000 Subject: [PATCH] Fixed TARGET_TEMPERATURE_RANGE bug --- custom_components/optispark/api.py | 6 +++--- custom_components/optispark/const.py | 2 +- custom_components/optispark/coordinator.py | 16 +++++++++------- custom_components/optispark/manifest.json | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/custom_components/optispark/api.py b/custom_components/optispark/api.py index 51aa6de..735ccb2 100644 --- a/custom_components/optispark/api.py +++ b/custom_components/optispark/api.py @@ -175,19 +175,19 @@ async def _api_wrapper( self, method: str, url: str, - data: dict | None = None, + data: dict, ): """Call the Lambda function.""" try: if 'dynamo_data' in data: data['dynamo_data'] = floats_to_decimal(data['dynamo_data']) - data = self.json_serialisable(data) + data_serialised = self.json_serialisable(data) async with async_timeout.timeout(40): response = await self._session.request( method=method, url=url, - json=data, + json=data_serialised, ) if response.status in (401, 403): raise OptisparkApiClientAuthenticationError( diff --git a/custom_components/optispark/const.py b/custom_components/optispark/const.py index 5594749..c48a9d9 100644 --- a/custom_components/optispark/const.py +++ b/custom_components/optispark/const.py @@ -5,7 +5,7 @@ NAME = "Optispark" DOMAIN = "optispark" -VERSION = "0.2.4" +VERSION = "0.2.5" ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/" LAMBDA_TEMP_CONTROLS = 'temp_controls' diff --git a/custom_components/optispark/coordinator.py b/custom_components/optispark/coordinator.py index 265cdaf..2d0d370 100644 --- a/custom_components/optispark/coordinator.py +++ b/custom_components/optispark/coordinator.py @@ -10,7 +10,7 @@ DataUpdateCoordinator, UpdateFailed, ) -from homeassistant.components.climate import HVACMode +from homeassistant.components.climate import ClimateEntityFeature from homeassistant.exceptions import ConfigEntryAuthFailed from .api import ( @@ -136,7 +136,8 @@ async def update_heat_pump_temperature(self, data): if self.heat_pump_target_temperature == temp: return LOGGER.debug('Change in target temperature!') - if climate_entity.hvac_mode == HVACMode.HEAT_COOL: + supports_target_temperature_range = climate_entity.supported_features & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE == ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + if supports_target_temperature_range: await climate_entity.async_set_temperature( target_temp_low=self.convert_climate_from_celcius(climate_entity, temp), target_temp_high=climate_entity.target_temperature_high) @@ -209,11 +210,12 @@ def heat_pump_target_temperature(self): Assumes that the heat pump is being used for heating. """ climate_entity = get_entity(self.hass, self._climate_entity_id) - match climate_entity.hvac_mode: - case HVACMode.HEAT_COOL: - temperature = climate_entity.target_temperature_low - case _: - temperature = climate_entity.target_temperature + supports_target_temperature_range = climate_entity.supported_features & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE == ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + if supports_target_temperature_range: + temperature = climate_entity.target_temperature_low + else: + temperature = climate_entity.target_temperature + return temperature @property diff --git a/custom_components/optispark/manifest.json b/custom_components/optispark/manifest.json index 3f25855..46c06b9 100644 --- a/custom_components/optispark/manifest.json +++ b/custom_components/optispark/manifest.json @@ -11,5 +11,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Big-Tree/HomeAssistant-OptiSpark/issues", "requirements": ["geopy==2.4.1"], - "version": "0.2.4" + "version": "0.2.5" }