Skip to content

Commit

Permalink
fix: Fixes crash when schedule contains custom profile
Browse files Browse the repository at this point in the history
  • Loading branch information
MislavMandaric committed Dec 3, 2021
1 parent e7b1914 commit 42449fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion custom_components/vaillant_vsmart/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@MislavMandaric"
],
"requirements": [
"vaillant-netatmo-api==0.7.0"
"vaillant-netatmo-api==0.7.1"
]
}
19 changes: 15 additions & 4 deletions custom_components/vaillant_vsmart/schedule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta

from vaillant_netatmo_api.thermostat import Program, TimeSlot
from vaillant_netatmo_api.thermostat import Program, TimeSlot, Zone


def map_program_to_schedule(
Expand All @@ -11,7 +11,11 @@ def map_program_to_schedule(
return {
"schedule_id": program.id,
"weekdays": ["daily"],
"timeslots": map_timetable_to_timeslots(profile_entity_id, daily_slots),
"timeslots": map_timetable_to_timeslots(
profile_entity_id,
daily_slots,
program.zones,
),
"repeat_type": "repeat",
"name": program.name,
"enabled": program.selected,
Expand Down Expand Up @@ -53,11 +57,18 @@ def map_timetable_to_next_entries(timetable: list[TimeSlot]) -> list[int]:


def map_timetable_to_timeslots(
profile_entity_id: str, timetable: list[TimeSlot]
profile_entity_id: str,
timetable: list[TimeSlot],
zones: list[Zone],
) -> list[dict]:
r = []

for i, time_slot in enumerate(timetable):
zone_name = ""
for zone in zones:
if zone.id == time_slot.id:
zone_name = zone.name

next_time_slot = timetable[(i + 1) % len(timetable)]
r.append(
{
Expand All @@ -67,7 +78,7 @@ def map_timetable_to_timeslots(
{
"service": "select.select_option",
"entity_id": profile_entity_id,
"service_data": {"option": time_slot.id.name},
"service_data": {"option": zone_name},
}
],
}
Expand Down
9 changes: 6 additions & 3 deletions custom_components/vaillant_vsmart/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ def entity_category(self) -> str:
def current_option(self) -> str | None:
"""Currently active profile in a schedule."""

zone_id = self._program.get_active_zone_id()
zone = self._program.get_active_zone()

return zone_id.name
if zone:
return zone.name

return None

@property
def options(self) -> list[str]:
"""All profiles available in the schedule."""

return [zone.id.name for zone in self._program.zones]
return [zone.name for zone in self._program.zones]

async def async_select_option(self, option: str) -> None:
"""Select different active profile."""
Expand Down

0 comments on commit 42449fd

Please sign in to comment.