Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
basbruss committed May 15, 2024
2 parents 644fda4 + 275e847 commit ba00579
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.4
uses: actions/checkout@v4.1.5

- name: 🚀 Run HACS validation
uses: hacs/action@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hassfest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/checkout@v4.1.4"
uses: "actions/checkout@v4.1.5"

- name: "Run hassfest validation"
uses: "home-assistant/actions/hassfest@master"
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
id-token: write
steps:
- name: "Checkout the repository"
uses: "actions/checkout@v4.1.4"
uses: "actions/checkout@v4.1.5"

- name: 🔢 Adjust version number
shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
zip adaptive_cover.zip -r ./
- name: "Upload the ZIP file to the release"
uses: softprops/action-gh-release@v2.0.4
uses: softprops/action-gh-release@v2.0.5
with:
files: ${{ github.workspace }}/custom_components/adaptive_cover/adaptive_cover.zip
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
19 changes: 9 additions & 10 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 @@ -97,9 +97,9 @@ def __init__(self, hass: HomeAssistant) -> None: # noqa: D107
self._climate_mode = self.config_entry.options.get(CONF_CLIMATE_MODE, False)
self._switch_mode = True if self._climate_mode else False
self._inverse_state = self.config_entry.options.get(CONF_INVERSE_STATE, False)
self._temp_toggle = False
self._control_toggle = True
self._manual_toggle = True
self._temp_toggle = None
self._control_toggle = None
self._manual_toggle = None
self.manual_reset = self.config_entry.options.get(
CONF_MANUAL_OVERRIDE_RESET, False
)
Expand Down Expand Up @@ -206,7 +206,7 @@ async def _async_update_data(self) -> AdaptiveCoverData:

self.default_state = round(NormalCoverState(cover_data).get_state())

if self.cover_state_change and self._manual_toggle and self.control_toggle:
if self.cover_state_change and self.manual_toggle and self.control_toggle:
self.manager.handle_state_change(
self.state_change_data,
self.state,
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
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ python = "^3.11"

[tool.poetry.group.dev.dependencies]
hass-nabucasa = "0.75.1"
pre-commit = "3.7.0"
pre-commit = "3.7.1"
pre-commit-hooks = "4.6.0"
pylint = "3.1.0"
pylint = "3.1.1"
ruff = "0.4.2"

[tool.poetry.urls]
Expand Down

0 comments on commit ba00579

Please sign in to comment.