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 Nov 3, 2024
2 parents b532d77 + bef4633 commit 54edfc8
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 25 deletions.
5 changes: 3 additions & 2 deletions custom_components/better_thermostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import logging
from asyncio import Lock
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, Config
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import ConfigType
import voluptuous as vol

from .utils.const import (
Expand All @@ -24,7 +25,7 @@
config_entry_update_listener_lock = Lock()


async def async_setup(hass: HomeAssistant, config: Config):
async def async_setup(hass: HomeAssistant, config: ConfigType):
"""Set up this integration using YAML is not supported."""
hass.data[DOMAIN] = {}
return True
Expand Down
12 changes: 6 additions & 6 deletions custom_components/better_thermostat/adapters/delegate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from importlib import import_module
from homeassistant.helpers.importlib import async_import_module
import logging

_LOGGER = logging.getLogger(__name__)


def load_adapter(self, integration, entity_id, get_name=False):
async def load_adapter(self, integration, entity_id, get_name=False):
"""Load adapter."""
if get_name:
self.name = "-"
Expand All @@ -13,9 +13,9 @@ def load_adapter(self, integration, entity_id, get_name=False):
integration = "generic"

try:
self.adapter = import_module(
self.adapter = await async_import_module(
self.hass,
"custom_components.better_thermostat.adapters." + integration,
package="better_thermostat",
)
_LOGGER.debug(
"better_thermostat %s: uses adapter %s for trv %s",
Expand All @@ -24,9 +24,9 @@ def load_adapter(self, integration, entity_id, get_name=False):
entity_id,
)
except Exception:
self.adapter = import_module(
self.adapter = await async_import_module(
self.hass,
"custom_components.better_thermostat.adapters.generic",
package="better_thermostat",
)
_LOGGER.info(
"better_thermostat %s: integration: %s isn't native supported, feel free to open an issue, fallback adapter %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 @@ -335,8 +335,8 @@ async def async_added_to_hass(self):
_calibration = 0
if trv["advanced"]["calibration"] == "hybrid_calibration":
_calibration = 2
_adapter = load_adapter(self, trv["integration"], trv["trv"])
_model_quirks = load_model_quirks(self, trv["model"], trv["trv"])
_adapter = await load_adapter(self, trv["integration"], trv["trv"])
_model_quirks = await load_model_quirks(self, trv["model"], trv["trv"])
self.real_trvs[trv["trv"]] = {
"calibration": _calibration,
"integration": trv["integration"],
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async def async_step_user(self, user_input=None):
"trv": trv,
"integration": _intigration,
"model": await get_device_model(self, trv),
"adapter": load_adapter(self, _intigration, trv),
"adapter": await load_adapter(self, _intigration, trv),
}
)
self.data[CONF_MODEL] = "/".join([x["model"] for x in self.trv_bundle])
Expand Down Expand Up @@ -438,7 +438,7 @@ async def async_step_advanced(
_default_calibration = "target_temp_based"
self.name = user_input.get(CONF_NAME, "-")

_adapter = load_adapter(
_adapter = await load_adapter(
self, _trv_config.get("integration"), _trv_config.get("trv")
)
if _adapter is not None:
Expand Down
4 changes: 3 additions & 1 deletion custom_components/better_thermostat/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ async def async_get_config_entry_diagnostics(
trv = hass.states.get(trv_id["trv"])
if trv is None:
continue
_adapter_name = load_adapter(hass, trv_id["integration"], trv_id["trv"], True)
_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,
Expand Down
58 changes: 58 additions & 0 deletions custom_components/better_thermostat/model_fixes/BTH-RM230Z.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Quirks for BTH-RM230Z
import logging
from homeassistant.helpers import device_registry as dr, entity_registry as er

_LOGGER = logging.getLogger(__name__)


def fix_local_calibration(self, entity_id, offset):
return offset


def fix_target_temperature_calibration(self, entity_id, temperature):
return temperature


async def override_set_hvac_mode(self, entity_id, hvac_mode):
return False


async def override_set_temperature(self, entity_id, temperature):
"""Bosch room thermostat BTH-RM230Z has a quirk where it needs to set both high
and low temperature, if heat and cool modes are available in newer Z2M versions.
"""
model = self.real_trvs[entity_id]["model"]
if model == "BTH-RM230Z":
_LOGGER.debug(
f"better_thermostat {self.name}: TRV {entity_id} device quirk bth-rm230z for set_temperature active"
)
entity_reg = er.async_get(self.hass)
entry = entity_reg.async_get(entity_id)

hvac_modes = entry.capabilities.get("hvac_modes", [])

_LOGGER.debug(
f"better_thermostat {self.name}: TRV {entity_id} device quirk bth-rm230z found hvac_modes {hvac_modes}"
)

if entry.platform == "mqtt" and "cool" in hvac_modes and "heat" in hvac_modes:
await self.hass.services.async_call(
"climate",
"set_temperature",
{
"entity_id": entity_id,
"target_temp_high": temperature,
"target_temp_low": temperature,
},
blocking=True,
context=self.context,
)
else:
await self.hass.services.async_call(
"climate",
"set_temperature",
{"entity_id": entity_id, "temperature": temperature},
blocking=True,
context=self.context,
)
return True
12 changes: 6 additions & 6 deletions custom_components/better_thermostat/model_fixes/model_quirks.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from importlib import import_module
from homeassistant.helpers.importlib import async_import_module
import logging

_LOGGER = logging.getLogger(__name__)


def load_model_quirks(self, model, entity_id):
async def load_model_quirks(self, model, entity_id):
"""Load model."""

# remove / from model
model = model.replace("/", "_")

try:
self.model_quirks = import_module(
self.model_quirks = await async_import_module(
self.hass,
"custom_components.better_thermostat.model_fixes." + model,
package="better_thermostat",
)
_LOGGER.debug(
"better_thermostat %s: uses quirks fixes for model %s for trv %s",
Expand All @@ -22,9 +22,9 @@ def load_model_quirks(self, model, entity_id):
entity_id,
)
except Exception:
self.model_quirks = import_module(
self.model_quirks = await async_import_module(
self.hass,
"custom_components.better_thermostat.model_fixes.default",
package="better_thermostat",
)
pass

Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"step": {
"user": {
"description": "Setup your Better Thermostat to integrate with Home Assistant\n**If you need more info: https://better-thermostat.org/configuration#first-step** ",
"description": "Setup your Better Thermostat to integrate with Home Assistant\n**If you need more info: https://better-thermostat.org/configuration#first-step**",
"data": {
"name": "Name",
"thermostat": "The real thermostat",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"step": {
"user": {
"description": "Einrichtung von Better Thermostat mit Home Assistant\n**Für mehr Informationen: https://better-thermostat.org/configuration#first-step** ",
"description": "Einrichtung von Better Thermostat mit Home Assistant\n**Für mehr Informationen: https://better-thermostat.org/configuration#first-step**",
"data": {
"name": "Name",
"thermostat": "Das reale Thermostat",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"step": {
"user": {
"description": "Setup your Better Thermostat to integrate with Home Assistant\n**If you need more info: https://better-thermostat.org/configuration#first-step** ",
"description": "Setup your Better Thermostat to integrate with Home Assistant\n**If you need more info: https://better-thermostat.org/configuration#first-step**",
"data": {
"name": "Name",
"thermostat": "The real thermostat",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"step": {
"user": {
"description": "Configurez Better Thermostat pour l'intégrer à Home Assistant\n**Si vous avez besoin de plus d'informations : https://better-thermostat.org/configuration#first-step** ",
"description": "Configurez Better Thermostat pour l'intégrer à Home Assistant\n**Si vous avez besoin de plus d'informations : https://better-thermostat.org/configuration#first-step**",
"data": {
"name": "Nom",
"thermostat": "Le vrai thermostat",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"step": {
"user": {
"description": "Skonfiguruj swój Better Thermostat do integracji z Home Assistant\n**Więcej informacji znajdziesz na: https://better-thermostat.org/configuration#first-step** ",
"description": "Skonfiguruj swój Better Thermostat do integracji z Home Assistant\n**Więcej informacji znajdziesz na: https://better-thermostat.org/configuration#first-step**",
"data": {
"name": "Nazwa",
"thermostat": "Twój termostat",
Expand Down
Loading

0 comments on commit 54edfc8

Please sign in to comment.