From 708a12fa0981ed5fabf1c0a24fd6e4584bc7d735 Mon Sep 17 00:00:00 2001 From: KartoffelToby Date: Fri, 3 Jan 2025 23:03:16 +0100 Subject: [PATCH] [TASK] add linting and fix some if typo --- .../better_thermostat/calibration.py | 7 ++++--- custom_components/better_thermostat/climate.py | 4 +++- .../better_thermostat/events/trv.py | 4 ++-- .../better_thermostat/utils/helpers.py | 16 +++++++--------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/custom_components/better_thermostat/calibration.py b/custom_components/better_thermostat/calibration.py index 2c5d682c..93ef3edb 100644 --- a/custom_components/better_thermostat/calibration.py +++ b/custom_components/better_thermostat/calibration.py @@ -63,7 +63,9 @@ def _convert_to_float(value): _cur_trv_temp_f = _convert_to_float(_cur_trv_temp_s) - _current_trv_calibration = _convert_to_float(self.real_trvs[entity_id]["last_calibration"]) + _current_trv_calibration = _convert_to_float( + self.real_trvs[entity_id]["last_calibration"] + ) if None in ( _current_trv_calibration, @@ -131,7 +133,6 @@ def _convert_to_float(value): t_max = float(self.real_trvs[entity_id]["local_calibration_max"]) _new_trv_calibration = max(t_min, min(_new_trv_calibration, t_max)) - _new_trv_calibration = _convert_to_float(_new_trv_calibration) _logmsg = ( @@ -184,7 +185,7 @@ def calculate_calibration_setpoint(self, entity_id) -> float | None: _cur_external_temp = self.cur_temp _cur_target_temp = self.bt_target_temp - _trv_temp_steps = 1 / ( self.real_trvs[entity_id]["target_temp_step"] or 0.5 ) + _trv_temp_steps = 1 / (self.real_trvs[entity_id]["target_temp_step"] or 0.5) if None in (_cur_target_temp, _cur_external_temp, _cur_trv_temp_s): return None diff --git a/custom_components/better_thermostat/climate.py b/custom_components/better_thermostat/climate.py index 0672b7d5..a6463f41 100644 --- a/custom_components/better_thermostat/climate.py +++ b/custom_components/better_thermostat/climate.py @@ -859,7 +859,9 @@ async def startup(self): ) self.real_trvs[trv]["target_temp_step"] = convert_to_float( str( - self.hass.states.get(trv).attributes.get("target_temp_step", 0.5) + self.hass.states.get(trv).attributes.get( + "target_temp_step", 0.5 + ) ), self.device_name, "startup", diff --git a/custom_components/better_thermostat/events/trv.py b/custom_components/better_thermostat/events/trv.py index 9611892c..1dedd9a8 100644 --- a/custom_components/better_thermostat/events/trv.py +++ b/custom_components/better_thermostat/events/trv.py @@ -368,8 +368,8 @@ def convert_outbound_states(self, entity_id, hvac_mode) -> dict | None: _new_heating_setpoint = self.real_trvs[entity_id]["min_temp"] hvac_mode = None if hvac_mode == HVACMode.OFF and ( - HVACMode.OFF not in _system_modes or - self.real_trvs[entity_id]["advanced"].get("no_off_system_mode") + HVACMode.OFF not in _system_modes + or self.real_trvs[entity_id]["advanced"].get("no_off_system_mode") ): _LOGGER.debug( f"better_thermostat {self.device_name}: sending 5°C to the TRV because this device has no system mode off and heater should be off" diff --git a/custom_components/better_thermostat/utils/helpers.py b/custom_components/better_thermostat/utils/helpers.py index 4ed99ef4..2643a14d 100644 --- a/custom_components/better_thermostat/utils/helpers.py +++ b/custom_components/better_thermostat/utils/helpers.py @@ -5,7 +5,6 @@ import math from datetime import datetime from enum import Enum -from typing import Union from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.entity_registry import async_entries_for_config_entry @@ -55,11 +54,11 @@ def mode_remap(self, entity_id, hvac_mode: str, inbound: bool = False) -> str: return hvac_mode trv_modes = self.real_trvs[entity_id]["hvac_modes"] - if not HVACMode.HEAT in trv_modes and HVACMode.HEAT_COOL in trv_modes: + if HVACMode.HEAT not in trv_modes and HVACMode.HEAT_COOL in trv_modes: # entity only supports HEAT_COOL, but not HEAT - need to translate - if not inbound and hvac_mode = HVACMode.HEAT: + if not inbound and hvac_mode == HVACMode.HEAT: return HVACMode.HEAT_COOL - if inbound and hvac_mode = HVACMode.HEAT_COOL: + if inbound and hvac_mode == HVACMode.HEAT_COOL: return HVACMode.HEAT if hvac_mode != HVACMode.AUTO: @@ -86,8 +85,8 @@ def heating_power_valve_position(self, entity_id): def convert_to_float( - value: Union[str, float], instance_name: str, context: str -) -> Union[float, None]: + value: str | float, instance_name: str, context: str +) -> float | None: """Convert value to float or print error message. Parameters @@ -117,7 +116,6 @@ def convert_to_float( return None - class rounding(Enum): # rounding functions that avoid errors due to using floats @@ -132,8 +130,8 @@ def nearest(x: float) -> float: def round_by_steps( - value: Union[float, None], steps: Union[float, None], f_rounding: rounding = rounding.nearest -) -> Union[float, None]: + value: float | None, steps: float | None, f_rounding: rounding = rounding.nearest +) -> float | None: """Round the value based on the allowed decimal 'steps'. Parameters