Skip to content

Commit

Permalink
Merge pull request #152 from basbruss/135-time-for-latest-close-wirho…
Browse files Browse the repository at this point in the history
…ut-sunset

Add end time variables
  • Loading branch information
basbruss authored May 16, 2024
2 parents 13a91cc + 82b19f9 commit 967bece
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Tilted blinds will only defect from the above approach if the inside temperature
| Start Time Entity | None | | The earliest moment a cover may be changed after midnight. *Overrides the `start_time` value* |
| Manual Override Duration | `15 min` | | Minimum duration for manual control status to remain active |
| Manual Override reset Timer | False | | Resets duration timer each time the position changes while the manual control status is active |
| End Time | `"00:00:00"` | | Latest time a cover can be adjusted each day |
| End Time Entity | None | | The latest moment a cover may be changed . *Overrides the `end_time` value* |

### Climate

Expand Down
11 changes: 9 additions & 2 deletions custom_components/adaptive_cover/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
CONF_DELTA_POSITION,
CONF_DELTA_TIME,
CONF_DISTANCE,
CONF_END_ENTITY,
CONF_END_TIME,
CONF_ENTITIES,
CONF_FOV_LEFT,
CONF_FOV_RIGHT,
Expand Down Expand Up @@ -278,6 +280,10 @@
CONF_MANUAL_OVERRIDE_DURATION, default={"minutes": 15}
): selector.DurationSelector(),
vol.Required(CONF_MANUAL_OVERRIDE_RESET, default=False): bool,
vol.Optional(CONF_END_TIME, default=None): selector.TimeSelector(),
vol.Optional(CONF_END_ENTITY): selector.EntitySelector(
selector.EntitySelectorConfig(domain=["sensor", "input_datetime"])
),
}
)

Expand Down Expand Up @@ -447,12 +453,13 @@ 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
CONF_START_ENTITY,
CONF_END_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
2 changes: 2 additions & 0 deletions custom_components/adaptive_cover/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
CONF_DELTA_TIME = "delta_time"
CONF_START_TIME = "start_time"
CONF_START_ENTITY = "start_entity"
CONF_END_TIME = "end_time"
CONF_END_ENTITY = "end_entity"
CONF_MANUAL_OVERRIDE_DURATION = "manual_override_duration"
CONF_MANUAL_OVERRIDE_RESET = "manual_override_reset"

Expand Down
28 changes: 26 additions & 2 deletions custom_components/adaptive_cover/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
CONF_DELTA_POSITION,
CONF_DELTA_TIME,
CONF_DISTANCE,
CONF_END_ENTITY,
CONF_END_TIME,
CONF_ENTITIES,
CONF_FOV_LEFT,
CONF_FOV_RIGHT,
Expand Down Expand Up @@ -163,6 +165,8 @@ async def _async_update_data(self) -> AdaptiveCoverData:
self.time_threshold = self.config_entry.options.get(CONF_DELTA_TIME, 2)
self.start_time = self.config_entry.options.get(CONF_START_TIME)
self.start_time_entity = self.config_entry.options.get(CONF_START_ENTITY)
self.end_time = self.config_entry.options.get(CONF_END_TIME)
self.end_time_entity = self.config_entry.options.get(CONF_END_ENTITY)
self.manual_reset = self.config_entry.options.get(
CONF_MANUAL_OVERRIDE_RESET, False
)
Expand Down Expand Up @@ -226,7 +230,7 @@ async def _async_update_data(self) -> AdaptiveCoverData:
if self.first_refresh and self.control_toggle:
for cover in self.entities:
if (
self.after_start_time
self.check_adaptive_time
and not self.manager.is_cover_manual(cover)
and self.check_position(cover)
):
Expand Down Expand Up @@ -261,7 +265,7 @@ async def async_handle_call_service(self, entity):
if (
self.check_position(entity)
and self.check_time_delta(entity)
and self.after_start_time
and self.check_adaptive_time
and not self.manager.is_cover_manual(entity)
):
await self.async_set_position(entity)
Expand Down Expand Up @@ -303,6 +307,11 @@ def get_blind_data(self):
)
return cover_data

@property
def check_adaptive_time(self):
"""Check if time is within start and end times."""
return self.before_end_time and self.after_start_time

@property
def after_start_time(self):
"""Check if time is after start time."""
Expand All @@ -318,6 +327,21 @@ def after_start_time(self):
return now >= time
return True

@property
def before_end_time(self):
"""Check if time is after start time."""
if self.end_time_entity is not None:
time = get_datetime_from_str(
get_safe_state(self.hass, self.end_time_entity)
)
now = dt.datetime.now(dt.UTC)
return now <= time
if self.end_time is not None:
time = get_datetime_from_str(self.end_time).time()
now = dt.datetime.now().time()
return now <= time
return True

def check_position(self, entity):
"""Check cover positions to reduce calls."""
if self._cover_type == "cover_tilt":
Expand Down
16 changes: 12 additions & 4 deletions custom_components/adaptive_cover/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
"start_time": "Starting time",
"start_entity": "Entity indicating starting time",
"manual_override_duration": "Duration of manual override",
"manual_override_reset": "Reset Manual override duration"
"manual_override_reset": "Reset Manual override duration",
"end_time": "End time",
"end_entity": "Entity indicating ending time"
},
"data_description": {
"delta_position": "Minimum change in position required before adjusting the cover's position",
"delta_time": "Minimum time interval between position changes; minimum is 2 minutes",
"start_time": "Starting time for each day; before this time, the cover will remain stationary",
"start_entity": "Entity representing starting time state, overriding the fixed start time set above. Useful for automating the start time with an entity",
"manual_override_duration": "The duration of manual control before resetting to automatic control",
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment"
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment",
"end_time": "Ending time for each day; after this time, the cover will remain stationary",
"end_entity": "Entity representing ending time state, overriding the fixed end time set above. Useful for automating the end time with an entity"
}
},
"vertical": {
Expand Down Expand Up @@ -179,15 +183,19 @@
"start_time": "Starting time",
"start_entity": "Entity indicating starting time",
"manual_override_duration": "Duration of manual override",
"manual_override_reset": "Reset Manual override duration"
"manual_override_reset": "Reset Manual override duration",
"end_time": "End time",
"end_entity": "Entity indicating ending time"
},
"data_description": {
"delta_position": "Minimum change in position required before adjusting the cover's position",
"delta_time": "Minimum time interval between position changes; minimum is 2 minutes",
"start_time": "Starting time for each day; before this time, the cover will remain stationary",
"start_entity": "Entity representing starting time state, overriding the fixed start time set above. Useful for automating the start time with an entity",
"manual_override_duration": "The duration of manual control before resetting to automatic control",
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment"
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment",
"end_time": "Ending time for each day; after this time, the cover will remain stationary",
"end_entity": "Entity representing ending time state, overriding the fixed end time set above. Useful for automating the end time with an entity"
}
},
"vertical": {
Expand Down
16 changes: 12 additions & 4 deletions custom_components/adaptive_cover/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
"start_time": "Starting time",
"start_entity": "Entity indicating starting time",
"manual_override_duration": "Duration of manual override",
"manual_override_reset": "Reset Manual override duration"
"manual_override_reset": "Reset Manual override duration",
"end_time": "End time",
"end_entity": "Entity indicating ending time"
},
"data_description": {
"delta_position": "Minimum change in position required before adjusting the cover's position",
"delta_time": "Minimum time interval between position changes; minimum is 2 minutes",
"start_time": "Starting time for each day; before this time, the cover will remain stationary",
"start_entity": "Entity representing starting time state, overriding the fixed start time set above. Useful for automating the start time with an entity",
"manual_override_duration": "The duration of manual control before resetting to automatic control",
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment"
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment",
"end_time": "Ending time for each day; after this time, the cover will remain stationary",
"end_entity": "Entity representing ending time state, overriding the fixed end time set above. Useful for automating the end time with an entity"
}
},
"vertical": {
Expand Down Expand Up @@ -179,15 +183,19 @@
"start_time": "Starting time",
"start_entity": "Entity indicating starting time",
"manual_override_duration": "Duration of manual override",
"manual_override_reset": "Reset Manual override duration"
"manual_override_reset": "Reset Manual override duration",
"end_time": "End time",
"end_entity": "Entity indicating ending time"
},
"data_description": {
"delta_position": "Minimum change in position required before adjusting the cover's position",
"delta_time": "Minimum time interval between position changes; minimum is 2 minutes",
"start_time": "Starting time for each day; before this time, the cover will remain stationary",
"start_entity": "Entity representing starting time state, overriding the fixed start time set above. Useful for automating the start time with an entity",
"manual_override_duration": "The duration of manual control before resetting to automatic control",
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment"
"manual_override_reset": "Option to reset the manual override duration after each manual adjustment; if disabled, the duration only applies to the first manual adjustment",
"end_time": "Ending time for each day; after this time, the cover will remain stationary",
"end_entity": "Entity representing ending time state, overriding the fixed end time set above. Useful for automating the end time with an entity"
}
},
"vertical": {
Expand Down
8 changes: 6 additions & 2 deletions custom_components/adaptive_cover/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
"start_time": "Starttijd",
"start_entity": "Entiteit die starttijd aangeeft",
"manual_override_duration": "Duur van handmatige overschrijving",
"manual_override_reset": "Reset handmatige overschrijvingsduur"
"manual_override_reset": "Reset handmatige overschrijvingsduur",
"end_time": "Eindtijd",
"end_entity": "Entiteit die eindtijd aangeeft"
},
"data_description": {
"delta_position": "Minimale verandering in positie vereist voordat de positie van de bekleding wordt aangepast",
"delta_time": "Minimale tijdsinterval tussen positieveranderingen; minimum is 2 minuten",
"start_time": "Starttijd voor elke dag; voor deze tijd blijft de bekleding stationair",
"start_entity": "Entiteit die de status van de starttijd vertegenwoordigt, die de hierboven ingestelde statische starttijd overschrijft. Handig voor het automatiseren van de starttijd met een entiteit",
"manual_override_duration": "De duur van handmatige bediening voordat wordt teruggekeerd naar automatische bediening",
"manual_override_reset": "Optie om de duur van handmatige overschrijving na elke handmatige aanpassing te resetten; als dit is uitgeschakeld, geldt de duur alleen voor de eerste handmatige aanpassing"
"manual_override_reset": "Optie om de duur van handmatige overschrijving na elke handmatige aanpassing te resetten; als dit is uitgeschakeld, geldt de duur alleen voor de eerste handmatige aanpassing",
"end_time": "Eindtijd voor elke dag; na deze tijd blijft de bekleding stationair",
"end_entity": "Entiteit die de status van de eindtijd vertegenwoordigt, die de hierboven ingestelde statische eindtijd overschrijft. Handig voor het automatiseren van de eindtijd met een entiteit"
}
},
"vertical": {
Expand Down

0 comments on commit 967bece

Please sign in to comment.