Skip to content

Commit

Permalink
Merge branch 'master' into feature/ha_compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KartoffelToby authored Jan 3, 2025
2 parents 57c852b + fbb884a commit ebe2c44
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 247 deletions.
60 changes: 47 additions & 13 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ labels: new bug
assignees: kartoffeltoby
---

### Prerequisites

* [ ] Model name of your Devices
* [ ] Output from Home Assistant Developer Tools state e.g.
* [ ] Output from Home Assistant Device Diagnostic from BT

```json
{
YOUR DEVICE DIAGNOSTICS JSON OUTPUT HERE
}
```
<!--
Please take care to fill the data as complete as possible.
The more information you provide, the higher the chances are that we can reporoduce and fix the issue for you!
-->

### Description

Expand All @@ -35,9 +28,50 @@ assignees: kartoffeltoby

<!-- What happens -->

### Versions
### Versions and HW

<!-- Provide both, HA (Home Assistant) and BT (Better Thermostat) version -->
Home Assistant:
Better Thermostat:
<!-- Thermostat valve model(s) -->
TRV(s):

### Debug data

**diagnostic data**
<!--
IMPORTANT:
Download and paste the diagnostic data from your Better Thermostat Entity(s) below.
https://www.home-assistant.io/docs/configuration/troubleshooting/#download-diagnostics
-->

```json
{
YOUR DEVICE DIAGNOSTICS JSON OUTPUT HERE
}
```

**debug log**
<!--
Depending on how complicated you issue is, it might be necessary to enable debug logging for BT,
reproduce the issue, and then upload this logfile here.
https://www.home-assistant.io/docs/configuration/troubleshooting/#enabling-debug-logging
-->

<!--
Alternatively your Home Assistant system log might be needed - Download here (top right corner):
https://my.home-assistant.io/redirect/logs
-> This might contain sensitive data though, so it's highly adviced *NOT* to share this file publicly.
-->

<!-- Provide both, HA and BT version -->
**graphs**
<!--
For issues in regards to the calibration / control routines, it is very helpful to also
provide statistics graph screenshots from HA for the following entities (from the time you had issues):
- BT climate entity
- TRV climate entities controlled by BT
- (optional) Valve opening states
-->

### Additional Information

Expand Down
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Related issue (check one):

- [ ] fixes #<issue number goes here>
- [ ] there is no related issue ticket
- [ ] There is no related issue ticket

## Checklist (check one):

Expand All @@ -14,17 +14,17 @@

## Test-Hardware list (for code changes)

<!-- Please specify your hardware/software which was used to test the code locally: -->
<!-- Please specify the hardware/software which was used to test the code locally: -->

HA Version:
Zigbee2MQTT Version:
TRV Hardware:

## New device mappings

<!-- If there was a new device mapping added, please make sure to fill in this checklist: -->
<!-- If a new device mapping has been added, please make sure to fill in this checklist: -->

- [ ] I avoided any changes to other device mappings
- [ ] There are no changes in `climate.py`

<!-- If you did change the `climate.py` please create a dedicated PR for this. -->
<!-- If you changed the `climate.py` please create a dedicated PR for this. -->
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ document in a pull request.

#### Nice to know

- Debuging is possible with the VSCode Debuger. Just run the HomeAssistant in Debugger and open browser on http://localhost:9123 (No task run needed)
- Debugging is possible with the VSCode Debugger. Just run the HomeAssistant in Debugger and open your browser to http://localhost:9123 (No task run needed)
- Update your local in devcontainer configuration.yaml to the current version of the repository to get the latest changes. -> Run "Sync configuration.yaml (Override local)" in Task Runner
- Test BT in a specific HA version -> Run "Install a specific version of Home Assistant" in Task Runner and the the version you want to test in the terminal promt.
- Test BT with the latest HA version -> Run "pgrade Home Assistant to latest dev" in Task Runner
- Test BT in a specific HA version -> Run "Install a specific version of Home Assistant" in Task Runner and the version you want to test in the terminal prompt.
- Test BT with the latest HA version -> Run "upgrade Home Assistant to latest dev" in Task Runner

## How Can I Contribute?

## New Adapter

If you want to add a new adapter, please create a new python file with the name of the adapter in the adapters folder. The file should contain all functions find in the generic.py. The if you adapter needs a special handling for one of the base functions, override it, if you can use generic functions, use them like:
If you want to add a new adapter, please create a new Python file with the name of the adapter in the adapters folder. The file should contain all functions found in the generic.py. If your adapter needs special handling for one of the base functions, override it, if you can use generic functions, use them like:

```python
async def set_temperature(self, entity_id, temperature):
Expand All @@ -55,4 +55,4 @@ https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html

## Setup

Install the pip install pre-commit used for pre-commit hooks.
Install the pip install pre-commit used for pre-commit hooks.
38 changes: 17 additions & 21 deletions custom_components/better_thermostat/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from custom_components.better_thermostat.utils.helpers import (
convert_to_float,
round_down_to_half_degree,
round_by_steps,
heating_power_valve_position,
)
Expand Down Expand Up @@ -42,6 +41,9 @@ def calculate_calibration_local(self, entity_id) -> float | None:
"""
_context = "_calculate_calibration_local()"

def _convert_to_float(value):
return convert_to_float(value, self.name, _context)

if None in (self.cur_temp, self.bt_target_temp):
return None

Expand All @@ -59,11 +61,9 @@ def calculate_calibration_local(self, entity_id) -> float | None:
_cur_external_temp = self.cur_temp
_cur_target_temp = self.bt_target_temp

_cur_trv_temp_f = convert_to_float(str(_cur_trv_temp_s), self.device_name, _context)
_cur_trv_temp_f = _convert_to_float(_cur_trv_temp_s)

_current_trv_calibration = convert_to_float(
str(self.real_trvs[entity_id]["last_calibration"]), self.device_name, _context
)
_current_trv_calibration = _convert_to_float(self.real_trvs[entity_id]["last_calibration"])

if None in (
_current_trv_calibration,
Expand Down Expand Up @@ -126,17 +126,13 @@ def calculate_calibration_local(self, entity_id) -> float | None:
# Adjust based on the steps allowed by the local calibration entity
_new_trv_calibration = round_by_steps(_new_trv_calibration, _calibration_steps)

# Compare against min/max
if _new_trv_calibration > float(self.real_trvs[entity_id]["local_calibration_max"]):
_new_trv_calibration = float(self.real_trvs[entity_id]["local_calibration_max"])
elif _new_trv_calibration < float(
self.real_trvs[entity_id]["local_calibration_min"]
):
_new_trv_calibration = float(self.real_trvs[entity_id]["local_calibration_min"])
# limit new setpoint within min/max of the TRV's range
t_min = float(self.real_trvs[entity_id]["local_calibration_min"])
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(
str(_new_trv_calibration), self.device_name, _context
)

_new_trv_calibration = _convert_to_float(_new_trv_calibration)

_logmsg = (
"better_thermostat %s: %s - new local calibration: %s | external_temp: %s, "
Expand Down Expand Up @@ -188,6 +184,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 )

if None in (_cur_target_temp, _cur_external_temp, _cur_trv_temp_s):
return None
Expand Down Expand Up @@ -236,13 +233,12 @@ def calculate_calibration_setpoint(self, entity_id) -> float | None:
_cur_external_temp - (_cur_target_temp + self.tolerance)
) * 8.0 # Reduced from 10.0 since we already subtract 2.0

_calibrated_setpoint = round_down_to_half_degree(_calibrated_setpoint)
_calibrated_setpoint = round_by_steps(_calibrated_setpoint, _trv_temp_steps)

# check if new setpoint is inside the TRV's range, else set to min or max
if _calibrated_setpoint < self.real_trvs[entity_id]["min_temp"]:
_calibrated_setpoint = self.real_trvs[entity_id]["min_temp"]
if _calibrated_setpoint > self.real_trvs[entity_id]["max_temp"]:
_calibrated_setpoint = self.real_trvs[entity_id]["max_temp"]
# limit new setpoint within min/max of the TRV's range
t_min = self.real_trvs[entity_id]["min_temp"]
t_max = self.real_trvs[entity_id]["max_temp"]
_calibrated_setpoint = max(t_min, min(_calibrated_setpoint, t_max))

_logmsg = (
"better_thermostat %s: %s - new setpoint calibration: %s | external_temp: %s, "
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ 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", 1)
self.hass.states.get(trv).attributes.get("target_temp_step", 0.5)
),
self.device_name,
"startup",
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def target_temperature_step(self) -> float | None:
Returns
-------
float
Steps of target temperature.
Step size of target temperature.
"""
if self.bt_target_temp_step is not None:
return self.bt_target_temp_step
Expand Down
8 changes: 4 additions & 4 deletions custom_components/better_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
CONF_CHILD_LOCK,
CONF_HEAT_AUTO_SWAPPED,
CONF_HEATER,
CONF_HOMATICIP,
CONF_HOMEMATICIP,
CONF_HUMIDITY,
CONF_MODEL,
CONF_NO_SYSTEM_MODE_OFF,
Expand Down Expand Up @@ -246,7 +246,7 @@ async def async_step_advanced(self, user_input=None, _trv_config=None):
] = bool
fields[
vol.Optional(
CONF_HOMATICIP, default=user_input.get(CONF_HOMATICIP, homematic)
CONF_HOMEMATICIP, default=user_input.get(CONF_HOMEMATICIP, homematic)
)
] = bool

Expand Down Expand Up @@ -523,8 +523,8 @@ async def async_step_advanced(
] = bool
fields[
vol.Optional(
CONF_HOMATICIP,
default=_trv_config["advanced"].get(CONF_HOMATICIP, homematic),
CONF_HOMEMATICIP,
default=_trv_config["advanced"].get(CONF_HOMEMATICIP, homematic),
)
] = bool

Expand Down
12 changes: 7 additions & 5 deletions custom_components/better_thermostat/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ async def async_get_config_entry_diagnostics(
trv = hass.states.get(trv_id["trv"])
if trv is None:
continue
_adapter_name = await load_adapter(
hass, trv_id["integration"], trv_id["trv"], True
)
trv_id["adapter"] = _adapter_name
# TODO: this does nothing but return trv_id["integration"] as adapter_name
# -> removing this for now, to fix diagnostic export
# _adapter_name = await load_adapter(
# hass, trv_id["integration"], trv_id["trv"], True
# )
# trv_id["adapter"] = _adapter_name
trvs[trv_id["trv"]] = {
"name": trv.name,
"state": trv.state,
"attributes": trv.attributes,
"bt_config": trv_id["advanced"],
"bt_adapter": trv_id["adapter"],
# "bt_adapter": trv_id["adapter"],
"bt_integration": trv_id["integration"],
"model": trv_id["model"],
}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/events/temperature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from custom_components.better_thermostat.utils.const import CONF_HOMATICIP
from custom_components.better_thermostat.utils.const import CONF_HOMEMATICIP
from ..utils.helpers import convert_to_float
from datetime import datetime
from homeassistant.helpers import issue_registry as ir
Expand Down Expand Up @@ -41,7 +41,7 @@ async def trigger_temperature_change(self, event):

try:
for trv in self.all_trvs:
if trv["advanced"][CONF_HOMATICIP]:
if trv["advanced"][CONF_HOMEMATICIP]:
_time_diff = 600
except KeyError:
pass
Expand Down
6 changes: 3 additions & 3 deletions custom_components/better_thermostat/events/trv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from datetime import datetime
import logging
from custom_components.better_thermostat.utils.const import CONF_HOMATICIP
from custom_components.better_thermostat.utils.const import CONF_HOMEMATICIP

from homeassistant.components.climate.const import (
HVACMode,
Expand Down Expand Up @@ -75,7 +75,7 @@ async def trigger_trv_change(self, event):
_time_diff = 5
try:
for trv in self.all_trvs:
if trv["advanced"][CONF_HOMATICIP]:
if trv["advanced"][CONF_HOMEMATICIP]:
_time_diff = 600
except KeyError:
pass
Expand Down Expand Up @@ -227,7 +227,7 @@ async def update_hvac_action(self):

# i don't know why this is here just for hometicip / wtom - 2023-08-23
# for trv in self.all_trvs:
# if trv["advanced"][CONF_HOMATICIP]:
# if trv["advanced"][CONF_HOMEMATICIP]:
# entity_id = trv["trv"]
# state = self.hass.states.get(entity_id)
# if state is None:
Expand Down
Loading

0 comments on commit ebe2c44

Please sign in to comment.