Skip to content

Commit

Permalink
make sure selected option updates after midnight
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Jun 30, 2024
1 parent 350c219 commit f2a99ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def display_options(self) -> list[str]:
ret.insert(0, NOSCHEDULE)
return ret

@property
def current_option(self) -> str:
if self._converted_option is not None:
return SchedulerOptionsHandler.convert_datetime(self._converted_option)
return NOSCHEDULE

@property
def options(self) -> list[datetime]:
now = datetime.now()
Expand Down
11 changes: 4 additions & 7 deletions custom_components/peaqev/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,26 @@ async def async_setup_entry(

entities = []
if hub.options.price.price_aware and not hub.options.peaqev_lite:
entities.append(PeaqSelectEntity('Scheduler next departure', hub))
entities.append(PeaqSelectEntity('Scheduler next departure', hub.scheduler_options_handler))
async_add_entities(entities)


class PeaqSelectEntity(SelectEntity, RestoreEntity):
def __init__(self, name, hub):
def __init__(self, name, options_handler):
self._attr_name = name
self.scheduler = hub.scheduler_options_handler
self.scheduler = options_handler
self._attr_options = self.scheduler.display_options
self._attr_current_option = None

async def async_update(self):
self._attr_options = self.scheduler.display_options
self._attr_current_option = self.scheduler.current_option
if self._attr_current_option not in self._attr_options:
self._attr_current_option = self._attr_options[0]

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
_LOGGER.debug('Selected option: %s', option)
# if hasattr(self.scheduler, 'charge_limit'):
# _LOGGER.debug('found it! %s', self.scheduler.charge_limit)
# else:
# _LOGGER.debug('not found')
await self.scheduler.async_handle_scheduler_departure_option(option)
self._attr_current_option = option

Expand Down

0 comments on commit f2a99ba

Please sign in to comment.