Skip to content

Commit

Permalink
Merge branch 'master' into fix/open-close_window
Browse files Browse the repository at this point in the history
  • Loading branch information
KartoffelToby authored Jan 3, 2025
2 parents 3189dd9 + 708a12f commit 0679245
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions custom_components/better_thermostat/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/events/trv.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,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"
Expand Down
16 changes: 7 additions & 9 deletions custom_components/better_thermostat/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -117,7 +116,6 @@ def convert_to_float(
return None



class rounding(Enum):
# rounding functions that avoid errors due to using floats

Expand All @@ -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
Expand Down

0 comments on commit 0679245

Please sign in to comment.