From 20369577f3403b99dab298979d3c35398640cff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Villagra?= Date: Tue, 23 Nov 2021 20:37:58 +0000 Subject: [PATCH] fix linter issues --- custom_components/localtuya/climate.py | 90 ++++++++++--------- custom_components/localtuya/const.py | 2 +- .../localtuya/translations/en.json | 4 +- 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/custom_components/localtuya/climate.py b/custom_components/localtuya/climate.py index 3deea4f..eaf6903 100644 --- a/custom_components/localtuya/climate.py +++ b/custom_components/localtuya/climate.py @@ -1,9 +1,7 @@ """Platform to locally control Tuya-based climate devices.""" import asyncio import logging -import json from functools import partial -import json import voluptuous as vol from homeassistant.components.climate import ( @@ -16,10 +14,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, - HVAC_MODE_COOL, - HVAC_MODE_HEAT_COOL, - HVAC_MODE_DRY, - HVAC_MODE_FAN_ONLY, SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, @@ -28,11 +22,7 @@ from homeassistant.components.climate.const import ( PRESET_NONE, PRESET_ECO, PRESET_AWAY, - PRESET_BOOST, - PRESET_COMFORT, PRESET_HOME, - PRESET_SLEEP, - PRESET_ACTIVITY, ) from homeassistant.const import ( ATTR_TEMPERATURE, @@ -55,7 +45,7 @@ from .const import ( CONF_TEMPERATURE_STEP, CONF_HVAC_MODE_DP, CONF_HVAC_MODE_SET, - CONF_EURISTIC_ACTION, + CONF_HEURISTIC_ACTION, CONF_HVAC_ACTION_DP, CONF_HVAC_ACTION_SET, CONF_ECO_DP, @@ -64,8 +54,6 @@ from .const import ( CONF_PRESET_SET, ) -from . import pytuya - _LOGGER = logging.getLogger(__name__) HVAC_MODE_SETS = { @@ -111,6 +99,7 @@ DEFAULT_TEMPERATURE_STEP = PRECISION_HALVES # Empirically tested to work for AVATTO thermostat MODE_WAIT = 0.1 + def flow_schema(dps): """Return schema used in config flow.""" return { @@ -125,26 +114,20 @@ def flow_schema(dps): [PRECISION_WHOLE, PRECISION_HALVES, PRECISION_TENTHS] ), vol.Optional(CONF_HVAC_MODE_DP): vol.In(dps), - vol.Optional(CONF_HVAC_MODE_SET): vol.In( - list(HVAC_MODE_SETS.keys()) - ), + vol.Optional(CONF_HVAC_MODE_SET): vol.In(list(HVAC_MODE_SETS.keys())), vol.Optional(CONF_HVAC_ACTION_DP): vol.In(dps), - vol.Optional(CONF_HVAC_ACTION_SET): vol.In( - list(HVAC_ACTION_SETS.keys()) - ), + vol.Optional(CONF_HVAC_ACTION_SET): vol.In(list(HVAC_ACTION_SETS.keys())), vol.Optional(CONF_ECO_DP): vol.In(dps), vol.Optional(CONF_ECO_VALUE): str, vol.Optional(CONF_PRESET_DP): vol.In(dps), - vol.Optional(CONF_PRESET_SET): vol.In( - list(PRESET_SETS.keys()) - ), + vol.Optional(CONF_PRESET_SET): vol.In(list(PRESET_SETS.keys())), vol.Optional(CONF_TEMPERATURE_UNIT): vol.In( [TEMPERATURE_CELSIUS, TEMPERATURE_FAHRENHEIT] ), vol.Optional(CONF_TARGET_PRECISION): vol.In( [PRECISION_WHOLE, PRECISION_HALVES, PRECISION_TENTHS] ), - vol.Optional(CONF_EURISTIC_ACTION, default=False): bool, + vol.Optional(CONF_HEURISTIC_ACTION): bool, } @@ -167,16 +150,24 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): self._preset_mode = None self._hvac_action = None self._precision = self._config.get(CONF_PRECISION, DEFAULT_PRECISION) - self._target_precision = self._config.get(CONF_TARGET_PRECISION, self._precision) + self._target_precision = self._config.get( + CONF_TARGET_PRECISION, self._precision + ) self._conf_hvac_mode_dp = self._config.get(CONF_HVAC_MODE_DP) - self._conf_hvac_mode_set = HVAC_MODE_SETS.get(self._config.get(CONF_HVAC_MODE_SET), {}) + self._conf_hvac_mode_set = HVAC_MODE_SETS.get( + self._config.get(CONF_HVAC_MODE_SET), {} + ) self._conf_preset_dp = self._config.get(CONF_PRESET_DP) self._conf_preset_set = PRESET_SETS.get(self._config.get(CONF_PRESET_SET), {}) self._conf_hvac_action_dp = self._config.get(CONF_HVAC_ACTION_DP) - self._conf_hvac_action_set = HVAC_ACTION_SETS.get(self._config.get(CONF_HVAC_ACTION_SET), {}) + self._conf_hvac_action_set = HVAC_ACTION_SETS.get( + self._config.get(CONF_HVAC_ACTION_SET), {} + ) self._conf_eco_dp = self._config.get(CONF_ECO_DP) self._conf_eco_value = self._config.get(CONF_ECO_VALUE, "ECO") - self._has_presets = self.has_config(CONF_ECO_DP) or self.has_config(CONF_PRESET_DP) + self._has_presets = self.has_config(CONF_ECO_DP) or self.has_config( + CONF_PRESET_DP + ) print("Initialized climate [{}]".format(self.name)) @property @@ -226,25 +217,32 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): @property def hvac_action(self): """Return the current running hvac operation if supported. + Need to be one of CURRENT_HVAC_*. """ - if self._config[CONF_EURISTIC_ACTION]: + if self._config.get(CONF_HEURISTIC_ACTION, False): if self._hvac_mode == HVAC_MODE_HEAT: - if self._current_temperature < (self._target_temperature - self._precision): + if self._current_temperature < ( + self._target_temperature - self._precision + ): self._hvac_action = CURRENT_HVAC_HEAT - if self._current_temperature == (self._target_temperature - self._precision): + if self._current_temperature == ( + self._target_temperature - self._precision + ): if self._hvac_action == CURRENT_HVAC_HEAT: self._hvac_action = CURRENT_HVAC_HEAT if self._hvac_action == CURRENT_HVAC_OFF: self._hvac_action = CURRENT_HVAC_OFF - if (self._current_temperature + self._precision) > self._target_temperature: + if ( + self._current_temperature + self._precision + ) > self._target_temperature: self._hvac_action = CURRENT_HVAC_OFF return self._hvac_action return self._hvac_action @property def preset_mode(self): - """Return current preset""" + """Return current preset.""" return self._preset_mode @property @@ -286,7 +284,9 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): """Set new target temperature.""" if ATTR_TEMPERATURE in kwargs and self.has_config(CONF_TARGET_TEMPERATURE_DP): temperature = round(kwargs[ATTR_TEMPERATURE] / self._target_precision) - await self._device.set_dp(temperature, self._config[CONF_TARGET_TEMPERATURE_DP]) + await self._device.set_dp( + temperature, self._config[CONF_TARGET_TEMPERATURE_DP] + ) def set_fan_mode(self, fan_mode): """Set new target fan mode.""" @@ -301,14 +301,18 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): await self._device.set_dp(True, self._dp_id) # Some thermostats need a small wait before sending another update await asyncio.sleep(MODE_WAIT) - await self._device.set_dp(self._conf_hvac_mode_set[hvac_mode], self._conf_hvac_mode_dp) + await self._device.set_dp( + self._conf_hvac_mode_set[hvac_mode], self._conf_hvac_mode_dp + ) async def async_set_preset_mode(self, preset_mode): """Set new target preset mode.""" if preset_mode == PRESET_ECO: await self._device.set_dp(self._conf_eco_value, self._conf_eco_dp) return - await self._device.set_dp(self._conf_preset_set[preset_mode], self._conf_preset_dp) + await self._device.set_dp( + self._conf_preset_set[preset_mode], self._conf_preset_dp + ) @property def min_temp(self): @@ -339,22 +343,25 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): ) if self._has_presets: - if self.has_config(CONF_ECO_DP) and self.dps_conf(CONF_ECO_DP) == self._conf_eco_value: + if ( + self.has_config(CONF_ECO_DP) + and self.dps_conf(CONF_ECO_DP) == self._conf_eco_value + ): self._preset_mode = PRESET_ECO else: - for preset,value in self._conf_preset_set.items(): # todo remove + for preset, value in self._conf_preset_set.items(): # todo remove if self.dps_conf(CONF_PRESET_DP) == value: self._preset_mode = preset break else: self._preset_mode = PRESET_NONE - """Update the HVAC status""" + # Update the HVAC status if self.has_config(CONF_HVAC_MODE_DP): if not self._state: self._hvac_mode = HVAC_MODE_OFF else: - for mode,value in self._conf_hvac_mode_set.items(): + for mode, value in self._conf_hvac_mode_set.items(): if self.dps_conf(CONF_HVAC_MODE_DP) == value: self._hvac_mode = mode break @@ -362,9 +369,10 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): # in case hvac mode and preset share the same dp self._hvac_mode = HVAC_MODE_AUTO - """Update the current action""" - for action,value in self._conf_hvac_action_set.items(): + # Update the current action + for action, value in self._conf_hvac_action_set.items(): if self.dps_conf(CONF_HVAC_ACTION_DP) == value: self._hvac_action = action + async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaClimate, flow_schema) diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index 131891c..8bc26cb 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -53,7 +53,7 @@ CONF_HVAC_MODE_DP = "hvac_mode_dp" CONF_HVAC_MODE_SET = "hvac_mode_set" CONF_PRESET_DP = "preset_dp" CONF_PRESET_SET = "preset_set" -CONF_EURISTIC_ACTION = "euristic_action" +CONF_HEURISTIC_ACTION = "heuristic_action" CONF_HVAC_ACTION_DP = "hvac_action_dp" CONF_HVAC_ACTION_SET = "hvac_action_set" CONF_ECO_DP = "eco_dp" diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 0c39ff4..a7fe191 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -91,7 +91,7 @@ "preset_set": "Presets Set (optional)", "eco_dp": "Eco DP (optional)", "eco_value": "Eco value (optional)", - "euristic_action": "Enable euristic action (optional)" + "heuristic_action": "Enable heuristic action (optional)" } } } @@ -160,7 +160,7 @@ "preset_set": "Presets Set (optional)", "eco_dp": "Eco DP (optional)", "eco_value": "Eco value (optional)", - "euristic_action": "Enable euristic action (optional)" + "heuristic_action": "Enable heuristic action (optional)" } }, "yaml_import": {