Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/window delay closed #1056

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions custom_components/better_thermostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CONF_HEATER,
CONF_NO_SYSTEM_MODE_OFF,
CONF_WINDOW_TIMEOUT,
CONF_WINDOW_TIMEOUT_AFTER,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,6 +87,12 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
config_entry.version = 5
hass.config_entries.async_update_entry(config_entry, data=new)

if config_entry.version == 5:
new = {**config_entry.data}
new[CONF_WINDOW_TIMEOUT_AFTER] = new[CONF_WINDOW_TIMEOUT]
config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, data=new)

_LOGGER.info("Migration to version %s successful", config_entry.version)

return True
4 changes: 4 additions & 0 deletions custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
CONF_TOLERANCE,
CONF_WEATHER,
CONF_WINDOW_TIMEOUT,
CONF_WINDOW_TIMEOUT_AFTER,
SERVICE_RESTORE_SAVED_TARGET_TEMPERATURE,
SUPPORT_FLAGS,
VERSION,
Expand Down Expand Up @@ -128,6 +129,7 @@ async def async_service_handler(self, data: ServiceCall):
entry.data.get(CONF_HUMIDITY, None),
entry.data.get(CONF_SENSOR_WINDOW, None),
entry.data.get(CONF_WINDOW_TIMEOUT, None),
entry.data.get(CONF_WINDOW_TIMEOUT_AFTER, None),
entry.data.get(CONF_WEATHER, None),
entry.data.get(CONF_OUTDOOR_SENSOR, None),
entry.data.get(CONF_OFF_TEMPERATURE, None),
Expand Down Expand Up @@ -195,6 +197,7 @@ def __init__(
humidity_sensor_entity_id,
window_id,
window_delay,
window_delay_after,
weather_entity,
outdoor_sensor,
off_temperature,
Expand All @@ -220,6 +223,7 @@ def __init__(
self.humidity_entity_id = humidity_sensor_entity_id
self.window_id = window_id or None
self.window_delay = window_delay or 0
self.window_delay_after = window_delay_after or 0
self.weather_entity = weather_entity or None
self.outdoor_sensor = outdoor_sensor or None
self.off_temperature = float(off_temperature) or None
Expand Down
60 changes: 52 additions & 8 deletions custom_components/better_thermostat/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import logging
import voluptuous as vol

from collections import OrderedDict
from homeassistant import config_entries
from homeassistant.const import CONF_NAME
from homeassistant.core import callback
from homeassistant.helpers import selector
from homeassistant.components.climate.const import HVACMode
from homeassistant.helpers import config_validation as cv


from .utils.bridge import load_adapter

Expand All @@ -23,18 +31,12 @@
CONF_VALVE_MAINTENANCE,
CONF_WEATHER,
CONF_WINDOW_TIMEOUT,
CONF_WINDOW_TIMEOUT_AFTER,
CONF_CALIBRATION_MODE,
CONF_TOLERANCE,
CalibrationMode,
CalibrationType,
)
from homeassistant import config_entries
from homeassistant.const import CONF_NAME
from homeassistant.core import callback
from homeassistant.helpers import selector
from homeassistant.components.climate.const import HVACMode
from homeassistant.helpers import config_validation as cv


from . import DOMAIN # pylint:disable=unused-import

Expand Down Expand Up @@ -87,7 +89,7 @@


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 5
VERSION = 6
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL

def __init__(self):
Expand Down Expand Up @@ -264,6 +266,18 @@ async def async_step_user(self, user_input=None):
else:
self.data[CONF_WINDOW_TIMEOUT] = 0

if CONF_WINDOW_TIMEOUT_AFTER in self.data:
self.data[CONF_WINDOW_TIMEOUT_AFTER] = (
int(
cv.time_period_dict(
user_input.get(CONF_WINDOW_TIMEOUT_AFTER, None)
).total_seconds()
)
or 0
)
else:
self.data[CONF_WINDOW_TIMEOUT_AFTER] = 0

if "base" not in errors:
for trv in self.heater_entity_id:
_intigration = await get_trv_intigration(self, trv)
Expand Down Expand Up @@ -324,6 +338,9 @@ async def async_step_user(self, user_input=None):
selector.EntitySelectorConfig(domain="weather", multiple=False)
),
vol.Optional(CONF_WINDOW_TIMEOUT): selector.DurationSelector(),
vol.Optional(
CONF_WINDOW_TIMEOUT_AFTER
): selector.DurationSelector(),
vol.Optional(
CONF_OFF_TEMPERATURE,
default=user_input.get(CONF_OFF_TEMPERATURE, 20),
Expand Down Expand Up @@ -515,6 +532,18 @@ async def async_step_user(self, user_input=None):
else:
self.updated_config[CONF_WINDOW_TIMEOUT] = 0

if CONF_WINDOW_TIMEOUT_AFTER in self.updated_config:
self.updated_config[CONF_WINDOW_TIMEOUT_AFTER] = (
int(
cv.time_period_dict(
user_input.get(CONF_WINDOW_TIMEOUT_AFTER, None)
).total_seconds()
)
or 0
)
else:
self.updated_config[CONF_WINDOW_TIMEOUT_AFTER] = 0

self.updated_config[CONF_OFF_TEMPERATURE] = user_input.get(
CONF_OFF_TEMPERATURE
)
Expand Down Expand Up @@ -620,6 +649,21 @@ async def async_step_user(self, user_input=None):
)
] = selector.DurationSelector()

_timeout = self.config_entry.data.get(CONF_WINDOW_TIMEOUT_AFTER, 0)
_timeout = str(cv.time_period_seconds(_timeout))
_timeout = {
"hours": int(_timeout.split(":", maxsplit=1)[0]),
"minutes": int(_timeout.split(":")[1]),
"seconds": int(_timeout.split(":")[2]),
}
fields[
vol.Optional(
CONF_WINDOW_TIMEOUT_AFTER,
default=_timeout,
description={"suggested_value": _timeout},
)
] = selector.DurationSelector()

fields[
vol.Optional(
CONF_OFF_TEMPERATURE,
Expand Down
1 change: 1 addition & 0 deletions custom_components/better_thermostat/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CONF_WEATHER = "weather"
CONF_OFF_TEMPERATURE = "off_temperature"
CONF_WINDOW_TIMEOUT = "window_off_delay"
CONF_WINDOW_TIMEOUT_AFTER = "window_off_delay_after"
CONF_OUTDOOR_SENSOR = "outdoor_sensor"
CONF_VALVE_MAINTENANCE = "valve_maintenance"
CONF_MIN_TEMP = "min_temp"
Expand Down
10 changes: 7 additions & 3 deletions custom_components/better_thermostat/events/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ async def window_queue(self):
window_event_to_process = await self.window_queue_task.get()
if window_event_to_process is not None:
if window_event_to_process:
# TODO: window open delay
_LOGGER.debug(
f"better_thermostat {self.name}: Window opened, waiting {self.window_delay} seconds before continuing"
)
await asyncio.sleep(self.window_delay)
else:
# TODO: window close delay
await asyncio.sleep(self.window_delay)
_LOGGER.debug(
f"better_thermostat {self.name}: Window closed, waiting {self.window_delay_after} seconds before continuing"
)
await asyncio.sleep(self.window_delay_after)
# remap off on to true false
current_window_state = True
if self.hass.states.get(self.window_id).state == STATE_OFF:
Expand Down
8 changes: 5 additions & 3 deletions custom_components/better_thermostat/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"window_sensors": "Window sensor",
"off_temperature": "The outdoor temperature when the thermostat turn off",
"tolerance": "Tolerance, to prevent the thermostat from turning on and off too often.",
"window_off_delay": "Delay before the thermostat turn off when the window is open and on when the window is closed",
"window_off_delay": "Delay before the thermostat turn off when the window is opened",
"window_off_delay_after": "Delay before the thermostat turn on when the window is closed",
"outdoor_sensor": "If you have an outdoor sensor, you can use it to get the outdoor temperature",
"weather": "Your weather entity to get the outdoor temperature"
}
Expand Down Expand Up @@ -62,7 +63,8 @@
"window_sensors": "Window Sensor",
"off_temperature": "The outdoor temperature when the thermostat turn off",
"tolerance": "Tolerance, to prevent the thermostat from turning on and off too often.",
"window_off_delay": "Delay before the thermostat turn off when the window is open and on when the window is closed",
"window_off_delay": "Delay before the thermostat turn off when the window is opened",
"window_off_delay_after": "Delay before the thermostat turn on when the window is closed",
"outdoor_sensor": "If you have an outdoor sensor, you can use it to get the outdoor temperature",
"valve_maintenance": "If your thermostat has no own maintenance mode, you can use this one",
"calibration": "The sort of calibration https://better-thermostat.org/configuration#second-step",
Expand Down Expand Up @@ -123,4 +125,4 @@
"description": "Set the target temperature to a temporay like night mode, and save the old one."
}
}
}
}
6 changes: 4 additions & 2 deletions custom_components/better_thermostat/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"window_sensors": "Fenstersensor(en)",
"off_temperature": "Außentemperatur, bei welcher das Thermostat abgeschaltet wird.",
"tolerance": "Toleranz, um zu verhindern, dass das Thermostat zu oft ein- und ausgeschaltet wird.",
"window_off_delay": "Wartezeit, bevor das Thermostat bei geöffnetem Fenster abgeschaltet bzw. bei geschlossendem Fenter angeschaltet wird.",
"window_off_delay": "Wartezeit, bevor das Thermostat bei geöffnetem Fenster abgeschaltet.",
"window_off_delay_after": "Wartezeit, bevor das Thermostat bei geschlossendem Fenter angeschaltet wird.",
"outdoor_sensor": "Wenn ein Außentemperaturssensor vorhanden ist, kann dieser anstelle der Wetter-Entität genutzt werden.",
"weather": "Die Wetter-Entität für die Außentemperatur."
}
Expand Down Expand Up @@ -63,7 +64,8 @@
"window_sensors": "Fenstersensor(en)",
"off_temperature": "Außentemperatur, bei welcher das Thermostat abgeschaltet wird.",
"tolerance": "Toleranz, um zu verhindern, dass das Thermostat zu oft ein- und ausgeschaltet wird.",
"window_off_delay": "Wartezeit, bevor das Thermostat bei geöffnetem Fenster abgeschaltet bzw. bei geschlossenem Fenter angeschaltet wird.",
"window_off_delay": "Wartezeit, bevor das Thermostat bei geöffnetem Fenster abgeschaltet.",
"window_off_delay_after": "Wartezeit, bevor das Thermostat bei geschlossendem Fenter angeschaltet wird.",
"outdoor_sensor": "Wenn ein Außentemperatursensor vorhanden ist, kann dieser anstelle der Wetter-Entität genutzt werden.",
"weather": "Die Wetter-Entität für die Außentemperatur.",
"valve_maintenance": "Wenn Ihr Thermostat keinen eigenen Wartungsmodus hat, können Sie diesen verwenden",
Expand Down
6 changes: 4 additions & 2 deletions custom_components/better_thermostat/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"window_sensors": "Window sensor",
"off_temperature": "The outdoor temperature when the thermostat turn off",
"tolerance": "Tolerance, to prevent the thermostat from turning on and off too often.",
"window_off_delay": "Delay before the thermostat turn off when the window is open and on when the window is closed",
"window_off_delay": "Delay before the thermostat turn off when the window is opened",
"window_off_delay_after": "Delay before the thermostat turn on when the window is closed",
"outdoor_sensor": "If you have an outdoor sensor, you can use it to get the outdoor temperature",
"weather": "Your weather entity to get the outdoor temperature"
}
Expand Down Expand Up @@ -63,7 +64,8 @@
"window_sensors": "Window Sensor",
"off_temperature": "The outdoor temperature when the thermostat turn off",
"tolerance": "Tolerance, to prevent the thermostat from turning on and off too often.",
"window_off_delay": "Delay before the thermostat turn off when the window is open and on when the window is closed",
"window_off_delay": "Delay before the thermostat turn off when the window is opened",
"window_off_delay_after": "Delay before the thermostat turn on when the window is closed",
"outdoor_sensor": "If you have an outdoor sensor, you can use it to get the outdoor temperature",
"valve_maintenance": "If your thermostat has no own maintenance mode, you can use this one",
"calibration": "The sort of calibration https://better-thermostat.org/configuration#second-step",
Expand Down
Loading