Skip to content

Commit

Permalink
Merge pull request #153 from basbruss/fix-time-state-converter
Browse files Browse the repository at this point in the history
Fix `input_datetime` helper error
  • Loading branch information
basbruss authored May 15, 2024
2 parents 888ebc8 + 59d0115 commit 6620614
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 5 additions & 1 deletion custom_components/adaptive_cover/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,13 @@ async def async_step_init(
async def async_step_automation(self, user_input: dict[str, Any] | None = None):
"""Manage automation options."""
if user_input is not None:
entities = [
CONF_START_ENTITY
]
self.optional_entities(entities, user_input)
self.options.update(user_input)
return await self._update_options()
return self.async_show_form(
return self.async_show_form(
step_id="automation",
data_schema=self.add_suggested_values_to_schema(
AUTOMATION_CONFIG, user_input or self.options
Expand Down
11 changes: 5 additions & 6 deletions custom_components/adaptive_cover/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
DOMAIN,
LOGGER,
)
from .helpers import get_datetime_from_state, get_last_updated, get_safe_state, get_time
from .helpers import get_datetime_from_str, get_last_updated, get_safe_state

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -307,14 +307,13 @@ def get_blind_data(self):
def after_start_time(self):
"""Check if time is after start time."""
if self.start_time_entity is not None:
time = get_datetime_from_state(
time = get_datetime_from_str(
get_safe_state(self.hass, self.start_time_entity)
)
now = dt.datetime.now(dt.UTC)
if now.date() == time.date():
return now >= time
now = dt.datetime.now()
return now >= time
if self.start_time is not None:
time = get_time(self.start_time).time()
time = get_datetime_from_str(self.start_time).time()
now = dt.datetime.now().time()
return now >= time
return True
Expand Down
13 changes: 4 additions & 9 deletions custom_components/adaptive_cover/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime as dt

import pandas as pd
from dateutil import parser
from homeassistant.core import HomeAssistant, split_entity_id


Expand All @@ -21,22 +22,16 @@ def get_domain(entity: str):
return domain


def get_time(time: str):
"""Convert string to datetime.time."""
if time is not None:
return dt.datetime.strptime(time, "%H:%M:%S")


def get_timedelta_str(string: str):
"""Convert string to timedelta."""
if string is not None:
return pd.to_timedelta(string)


def get_datetime_from_state(state: str):
def get_datetime_from_str(string: str):
"""Convert datetime string to datetime."""
if state is not None:
return dt.datetime.strptime(state, "%Y-%m-%dT%H:%M:%S%z")
if string is not None:
return parser.parse(string, ignoretz=True)


def get_last_updated(entity_id: str, hass: HomeAssistant):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/adaptive_cover/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:
setattr(self.coordinator, self._key, True)
if self._key == "control_toggle" and kwargs.get("added") is not True:
for entity in self.coordinator.entities:
if not self.coordinator.manager.is_cover_manual(entity):
if not self.coordinator.manager.is_cover_manual(entity) and self.coordinator.after_start_time:
await self.coordinator.async_set_position(entity)
await self.coordinator.async_refresh()
self.schedule_update_ha_state()
Expand Down

0 comments on commit 6620614

Please sign in to comment.