Skip to content

Commit aae2f74

Browse files
committed
Refactor settings
1 parent 6ea4e50 commit aae2f74

4 files changed

Lines changed: 39 additions & 29 deletions

File tree

src/evohome_helper/evohome.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def is_in_schedule_grace_period(location=None):
102102
)
103103

104104
since_switch_point = now - switch_point
105-
if since_switch_point.total_seconds() < settings.HEATING_SCHEDULE_GRACE_TIME:
105+
if since_switch_point.total_seconds() < settings.PRESENCE_HEATING_SCHEDULE_GRACE_TIME:
106106
return True
107107

108108
return False
@@ -165,7 +165,7 @@ def _get_current_zone_switch_point_from_schedule(zone):
165165
if zone_switch_point_temperature == previous_zone_switch_point_temperature:
166166
continue
167167

168-
if zone_switch_point_temperature <= settings.HEATING_SCHEDULE_OFF_TEMP:
168+
if _is_considered_off(zone_switch_point_temperature):
169169
continue
170170

171171
if zone_switch_point_datetime > now or zone_switch_point_datetime < last_switch_point_datetime:
@@ -190,6 +190,10 @@ def get_zones(location):
190190
yield zone
191191

192192

193+
def _is_considered_off(temperature):
194+
return temperature <= settings.EVOHOME_OFF_TEMP_THRESHOLD
195+
196+
193197
def _is_override_enabled(control_system):
194198
current_mode = ThermostatStatuses.get_by_mode(control_system.systemModeStatus["mode"])
195199
if current_mode in [ThermostatStatuses.away, ThermostatStatuses.day_off, ThermostatStatuses.off]:
@@ -204,33 +208,32 @@ def _is_override_enabled(control_system):
204208

205209

206210
def _is_normal_heating_needed(location):
207-
eco_temperature = settings.HEATING_ECO_TEMPERATURE
208-
if eco_temperature is None:
211+
if not settings.AUTO_ECO_ENABLED:
209212
return True
210213

214+
outside_temp_threshold = settings.AUTO_ECO_OUTSIDE_TEMP_THRESHOLD
215+
inside_temp_diff = settings.AUTO_ECO_INSIDE_TEMP_DIFF
211216
highest_set_point_temp = _get_highest_set_point_temp(location)
212217

213218
# all zones are off?
214-
if highest_set_point_temp <= settings.HEATING_SCHEDULE_OFF_TEMP:
219+
if _is_considered_off(highest_set_point_temp):
215220
return True
216221

217-
outside_current_temperature = weather.get_temperature_info()
222+
# can we fetch a valid temperature?
223+
outside_current_temp = weather.get_temperature()
224+
if outside_current_temp <= -99:
225+
return True
218226

219227
logger.debug(
220228
"current outside temperature: %s degrees celsius",
221-
outside_current_temperature,
229+
outside_current_temp,
222230
)
223231

224232
# are we below the eco mode threshold?
225-
if outside_current_temperature < eco_temperature:
233+
if outside_current_temp < outside_temp_threshold:
226234
return True
227235

228-
try:
229-
temperature_offset = float(settings.HEATING_ECO_TEMPERATURE_OFFSET or 0.0)
230-
except (TypeError, ValueError):
231-
temperature_offset = 0.0
232-
233-
return outside_current_temperature + temperature_offset < highest_set_point_temp
236+
return outside_current_temp + inside_temp_diff < highest_set_point_temp
234237

235238

236239
def _get_highest_set_point_temp(location=None):

src/evohome_helper/presence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def is_someone_home():
1919
def is_in_away_grace_period():
2020
for entity_id in settings.HOMEASSISTANT_PRESENCE_ENTITIES:
2121
seconds_since_last_seen = _get_data(entity_id).get("seconds_since_last_seen")
22-
if seconds_since_last_seen and seconds_since_last_seen <= settings.LAST_HOME_GRACE_TIME:
22+
if seconds_since_last_seen and seconds_since_last_seen <= settings.PRESENCE_LAST_HOME_GRACE_TIME:
2323
return True
2424

2525
return False

src/evohome_helper/weather.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88

99

1010
@return_cache(refresh_interval=1800)
11-
def get_temperature_info():
12-
url = f"{settings.HOMEASSISTANT_URL}/api/states/{settings.HOMEASSISTANT_WEATHER_ENTITY}"
11+
def get_temperature():
12+
current_temperature = -99
13+
14+
ha_weather_entity = settings.HOMEASSISTANT_AUTO_ECO_WEATHER_ENTITY
15+
if ha_weather_entity is None:
16+
return current_temperature
17+
18+
url = f"{settings.HOMEASSISTANT_URL}/api/states/{ha_weather_entity}"
1319
headers = {
1420
"Authorization": f"Bearer {settings.HOMEASSISTANT_TOKEN}",
1521
"content-type": "application/json",
1622
}
1723

18-
current_temperature = -99
19-
2024
try:
2125
response = requests.get(
2226
url,

src/settings.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import json
22
import os
33

4+
# reads app configuration from home assistant
45
with open("/data/options.json") as f:
56
add_on_config = json.load(f)
67

7-
EVOHOME_LOCATION_NAME = add_on_config["evohome_location_name"]
8-
EVOHOME_USERNAME = add_on_config["evohome_username"]
9-
EVOHOME_PASSWORD = add_on_config["evohome_password"]
8+
EVOHOME_LOCATION_NAME = add_on_config["evohome.location_name"]
9+
EVOHOME_USERNAME = add_on_config["evohome.username"]
10+
EVOHOME_PASSWORD = add_on_config["evohome.password"]
11+
EVOHOME_OFF_TEMP_THRESHOLD = add_on_config["evohome.off_temp_threshold"]
1012

1113
HOMEASSISTANT_URL = "http://supervisor/core"
1214
HOMEASSISTANT_TOKEN = os.environ["SUPERVISOR_TOKEN"]
13-
HOMEASSISTANT_PRESENCE_ENTITIES = add_on_config["presence_entities"]
14-
HOMEASSISTANT_WEATHER_ENTITY = add_on_config["weather_entity"]
15+
HOMEASSISTANT_PRESENCE_ENTITIES = add_on_config["presence.entities"]
16+
HOMEASSISTANT_AUTO_ECO_WEATHER_ENTITY = add_on_config["auto_eco.weather_entity"]
1517

16-
LAST_HOME_GRACE_TIME = add_on_config["last_home_grace_time"]
17-
HEATING_SCHEDULE_GRACE_TIME = add_on_config["heating_schedule_grace_time"]
18-
HEATING_SCHEDULE_OFF_TEMP = add_on_config["heating_schedule_off_temp"]
19-
HEATING_ECO_TEMPERATURE = add_on_config["heating_eco_temperature"]
20-
HEATING_ECO_TEMPERATURE_OFFSET = add_on_config["heating_eco_temperature_offset"]
18+
PRESENCE_LAST_HOME_GRACE_TIME = add_on_config["presence.last_home_grace_time"]
19+
PRESENCE_HEATING_SCHEDULE_GRACE_TIME = add_on_config["presence.heating_schedule_grace_time"]
20+
21+
AUTO_ECO_ENABLED = add_on_config["auto_eco.enabled"]
22+
AUTO_ECO_OUTSIDE_TEMP_THRESHOLD = add_on_config["auto_eco.outside_temp_threshold"]
23+
AUTO_ECO_INSIDE_TEMP_DIFF = add_on_config["auto_eco.inside_temp_diff"]

0 commit comments

Comments
 (0)