Skip to content

Commit

Permalink
More readable code
Browse files Browse the repository at this point in the history
  • Loading branch information
myztillx authored and nkgilley committed Jan 11, 2023
1 parent 81d573b commit adbf375
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pyecobee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,10 @@ def update_climate_sensors(self, index: int, climate_name: str, sensor_names: li
programs: dict = self.thermostats[index]["program"]
# Remove currentClimateRef key.
programs.pop("currentClimateRef", None)
program_to_edit = next(
climate for climate in programs["climates"] if climate["name"] == climate_name)

for i, climate in enumerate(programs["climates"]):
if climate["name"] == climate_name:
climate_index = i
"""Update climate sensors with sensor_names list."""
sensor_list = []
for name in sensor_names:
Expand All @@ -710,7 +711,13 @@ def update_climate_sensors(self, index: int, climate_name: str, sensor_names: li
if sensor["name"] == name:
sensor_list.append(
{"id": "{}:1".format(sensor["id"]), "name": name})
program_to_edit["sensors"] = sensor_list
try:
programs["climates"][climate_index]["sensors"] = sensor_list
except UnboundLocalError:
"""This would occur if the climate_index was not assigned
because the climate name does not exist in the program climates."""
return

"""Updates Climate"""
body = {
"selection": {
Expand Down

0 comments on commit adbf375

Please sign in to comment.