Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nobbi1991 authored Dec 14, 2024
2 parents 3e76c9b + 23627a7 commit c7a79f1
Show file tree
Hide file tree
Showing 31 changed files with 456 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ updates:
- dependency-name: "*"
update-types:
- "version-update:semver-patch"
- package-manager: "github-actions"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
environment: pypi
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"

Expand Down
29 changes: 17 additions & 12 deletions .github/workflows/update_pre_commit_hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,63 @@ name: Update pre-commit hooks

on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight UTC
push:
branches:
- main # Runs when changes are pushed to the main branch
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
update-pre-commit-hooks:
runs-on: ubuntu-latest

steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4

# Install pre-commit
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit autoupdate
# Run pre-commit autoupdate to update the hook versions
run: pre-commit autoupdate

# Set git user identity to avoid "empty ident name" error
- name: Set Git user identity
- name: Set git user identity
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
- name: Check for changes and push updates
id: check-for-changes
run: |
# Check for any changes in the working directory or staged changes
if git diff --quiet && git diff --cached --quiet; then
echo "No changes detected, skipping commit."
echo "::set-output name=changes_found::false"
exit 0
fi
# If changes are detected, continue with committing and pushing
BRANCH_NAME="pre-commit-updates"
git fetch origin
if git rev-parse --verify origin/$BRANCH_NAME; then
echo "Branch $BRANCH_NAME exists, switching to it."
git stash
git checkout $BRANCH_NAME
else
echo "Branch $BRANCH_NAME does not exist, creating it."
git checkout -b $BRANCH_NAME
fi
# Commit and push changes
git add .pre-commit-config.yaml
git commit -m 'Update pre-commit hook versions'
git push -u origin $BRANCH_NAME
echo "::set-output name=changes_found::true"
- name: Create pull request
if: steps.check-for-changes.outputs.changes_found == 'true'
uses: peter-evans/create-pull-request@v7
with:
title: 'Update pre-commit hook versions'
body: 'Automated update of pre-commit hooks'
branch: ${{ github.ref_name }}
delete-branch: true
commit-message: 'Update pre-commit hook versions'
labels: 'pre-commit, automated'
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Version 7.1.1 - dd.12.2024
# Version 7.2.0 - dd.12.2024

# Features

- added rule `habapp_rules.actors.shading.ReferenceRun` to trigger the reference run for blinds every month
- added rule `habapp_rules.system.task.RecurringTask` to trigger recurring tasks

# Bugfix

- removed timezone from all datetime.items, since timezone makes no sense in the OpenHAB context

# Version 7.1.0 - 01.12.2024

# Features
Expand Down
5 changes: 1 addition & 4 deletions habapp_rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

import pathlib

import pytz

__version__ = "7.1.1"
__version__ = "7.2.0"
BASE_PATH = pathlib.Path(__file__).parent.parent.resolve()
TIMEZONE = pytz.timezone("Europe/Berlin")
15 changes: 15 additions & 0 deletions habapp_rules/actors/config/shading.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,18 @@ class SlatValueConfig(habapp_rules.core.pydantic_base.ConfigBase):

items: SlatValueItems = pydantic.Field(..., description="items for slat values for sun protection")
parameter: SlatValueParameter = pydantic.Field(SlatValueParameter(), description="parameter for slat values for sun protection")


class ReferenceRunItems(habapp_rules.core.pydantic_base.ItemBase):
"""Items for reference run."""

trigger_run: HABApp.openhab.items.SwitchItem = pydantic.Field(..., description="item for triggering the reference run")
last_run: HABApp.openhab.items.DatetimeItem = pydantic.Field(..., description="item for date/time of the last run")
presence_state: HABApp.openhab.items.StringItem = pydantic.Field(..., description="item for presence state")


class ReferenceRunConfig(habapp_rules.core.pydantic_base.ConfigBase):
"""Config for reference run."""

items: ReferenceRunItems = pydantic.Field(..., description="items for reference run")
parameter: None = None
9 changes: 4 additions & 5 deletions habapp_rules/actors/irrigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import habapp_rules.actors.config.irrigation
import habapp_rules.core.exceptions
import habapp_rules.core.logger
from habapp_rules import TIMEZONE

LOGGER = logging.getLogger(__name__)

Expand All @@ -19,9 +18,9 @@ class Irrigation(HABApp.Rule):
# Items:
Switch I999_valve "Valve state" {channel="some_channel_config"}
Switch I999_irrigation_active "Irrigation active"
Number I999_irrigation_hour "Start hour [%d]"
Number I999_irrigation_minute "Start minute[%d]"
Number I999_irrigation_duration "Duration [%d]"
Number I999_irrigation_hour "Start hour"
Number I999_irrigation_minute "Start minute"
Number I999_irrigation_duration "Duration"
# Config:
config = habapp_rules.actors.config.irrigation.IrrigationConfig(
Expand Down Expand Up @@ -84,7 +83,7 @@ def _get_target_valve_state(self) -> bool:
repetitions = self._config.items.repetitions.value if self._config.items.repetitions else 0
brake = int(self._config.items.brake.value) if self._config.items.brake else 0

now = datetime.datetime.now(tz=TIMEZONE)
now = datetime.datetime.now()
hour = int(self._config.items.hour.value)
minute = int(self._config.items.minute.value)
duration = int(self._config.items.duration.value)
Expand Down
4 changes: 2 additions & 2 deletions habapp_rules/actors/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class LightSwitch(_LightBase):
}
# Items:
Switch I01_01_Light "Light [%s]" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Switch I01_01_Light "Light" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Switch I00_00_Light_manual "Light manual"
# Config:
Expand Down Expand Up @@ -486,7 +486,7 @@ class LightDimmer(_LightBase):
}
# Items:
Dimmer I01_01_Light "Light [%s]" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Dimmer I01_01_Light "Light" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Dimmer I01_01_Light_ctr "Light ctr" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light_ctr"}
Dimmer I01_01_Light_group "Light Group" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light_group"}
Switch I00_00_Light_manual "Light manual"
Expand Down
5 changes: 2 additions & 3 deletions habapp_rules/actors/light_hcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import habapp_rules.core.state_machine_rule
import habapp_rules.core.type_of_day
import habapp_rules.system
from habapp_rules import TIMEZONE

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -209,7 +208,7 @@ class HclElevation(_HclBase):
"""Sun elevation based HCL.
# Items:
Number Elevation "Elevation [%s]" {channel="astro:sun:home:position#elevation"}
Number Elevation "Elevation" {channel="astro:sun:home:position#elevation"}
Number HCL_Color_Elevation "HCL Color Elevation"
Switch HCL_Color_Elevation_manual "HCL Color Elevation manual"
Expand Down Expand Up @@ -326,7 +325,7 @@ def _get_hcl_color(self) -> int | None:
Returns:
HCL light color
"""
current_time = datetime.datetime.now(TIMEZONE)
current_time = datetime.datetime.now()

if self._one_hour_later(current_time):
current_time -= datetime.timedelta(hours=1)
Expand Down
66 changes: 57 additions & 9 deletions habapp_rules/actors/shading.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Rules to manage shading objects."""

import abc
import datetime
import logging
import time
import typing
Expand Down Expand Up @@ -360,11 +361,11 @@ class Shutter(_ShadingBase):
}
# Items:
Rollershutter shading_position "Shading position [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position"}
Rollershutter shading_position_ctr "Shading position ctr [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position_ctr"}
Rollershutter shading_position "Shading position" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position"}
Rollershutter shading_position_ctr "Shading position ctr" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position_ctr"}
Dimmer shading_slat "Shading slat" <slat> {channel="knx:device:bridge:KNX_Shading:shading_slat"}
Switch shading_manual "Shading manual"
Rollershutter shading_all_ctr "Shading all ctr [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_group_all_ctr"}
Rollershutter shading_all_ctr "Shading all ctr" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_group_all_ctr"}
Switch shading_hand_manual "Shading in Hand / Manual state" {channel="knx:device:bridge:KNX_Shading:shading_hand_manual_ctr"}
# Config:
Expand Down Expand Up @@ -425,11 +426,11 @@ class Raffstore(_ShadingBase):
}
# Items:
Rollershutter shading_position "Shading position [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position"}
Rollershutter shading_position_ctr "Shading position ctr [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position_ctr"}
Dimmer shading_slat "Shading slat [%s %%]" <slat> {channel="knx:device:bridge:KNX_Shading:shading_slat"}
Rollershutter shading_position "Shading position" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position"}
Rollershutter shading_position_ctr "Shading position ctr" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_position_ctr"}
Dimmer shading_slat "Shading slat" <slat> {channel="knx:device:bridge:KNX_Shading:shading_slat"}
Switch shading_manual "Shading manual"
Rollershutter shading_all_ctr "Shading all ctr [%s %%]" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_group_all_ctr"}
Rollershutter shading_all_ctr "Shading all ctr" <rollershutter> {channel="knx:device:bridge:KNX_Shading:shading_group_all_ctr"}
Switch shading_hand_manual "Shading in Hand / Manual state" {channel="knx:device:bridge:KNX_Shading:shading_hand_manual_ctr"}
# Config:
Expand Down Expand Up @@ -603,8 +604,8 @@ class SlatValueSun(HABApp.Rule):
"""Rules class to get slat value depending on sun elevation.
# Items:
Number elevation "Sun elevation [%s]" <sun> {channel="astro...}
Number sun_protection_slat "Slat value [%s %%]" <slat>
Number elevation "Sun elevation" <sun> {channel="astro...}
Number sun_protection_slat "Slat value" <slat>
# Config
config = habapp_rules.actors.config.shading.SlatValueConfig(
Expand Down Expand Up @@ -685,3 +686,50 @@ def _cb_summer_winter(self, event: HABApp.openhab.events.ItemStateChangedEvent)
"""
self._slat_characteristic_active = self._config.parameter.elevation_slat_characteristic_summer if event.value == "ON" else self._config.parameter.elevation_slat_characteristic
self.__send_slat_value()


class ReferenceRun(HABApp.Rule):
"""Rule to trigger a reference run for blinds every month.
# Items:
Switch trigger_run "trigger reference run"
DateTime last_run "last run"
String presence_state "Presence state"
# Config
config = habapp_rules.actors.config.shading.ReferenceRunConfig(
items=habapp_rules.actors.config.shading.ReferenceRunItems(
trigger_run="trigger_run",
presence_state="presence_state",
last_run="last_run",
)
)
# Rule init:
habapp_rules.actors.shading.ReferenceRun(config)
"""

def __init__(self, config: habapp_rules.actors.config.shading.ReferenceRunConfig) -> None:
"""Init ReferenceRun.
Args:
config: configuration of reference run rule
"""
self._config = config
HABApp.Rule.__init__(self)

self._config.items.presence_state.listen_event(self._cb_presence_state, HABApp.openhab.events.ItemStateChangedEventFilter())

def _cb_presence_state(self, event: HABApp.openhab.events.ItemStateChangedEvent) -> None:
"""Callback which is called if presence state changed.
Args:
event: presence state event
"""
if event.value == habapp_rules.system.PresenceState.ABSENCE.value:
last_run = self._config.items.last_run.value or datetime.datetime.min
current_time = datetime.datetime.now()

if last_run.year < current_time.year or last_run.month < current_time.month:
self._config.items.trigger_run.oh_send_command("ON")
self._config.items.last_run.oh_send_command(current_time)
8 changes: 4 additions & 4 deletions habapp_rules/actors/state_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class StateObserverSwitch(_StateObserverBase):
}
# Items:
Switch I01_01_Switch "Switch [%s]" {channel="knx:device:bridge:T00_99_OpenHab_DimmerSwitch:switch"}
Switch I01_01_Switch "Switch" {channel="knx:device:bridge:T00_99_OpenHab_DimmerSwitch:switch"}
# Rule init:
habapp_rules.actors.state_observer.StateObserverSwitch("I01_01_Switch", callback_on, callback_off)
Expand Down Expand Up @@ -249,7 +249,7 @@ class StateObserverDimmer(_StateObserverBase):
}
# Items:
Dimmer I01_01_Light "Light [%s]" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Dimmer I01_01_Light "Light" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light"}
Dimmer I01_01_Light_ctr "Light ctr" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light_ctr"}
Dimmer I01_01_Light_group "Light Group" {channel="knx:device:bridge:T00_99_OpenHab_DimmerObserver:light_group"}
Expand Down Expand Up @@ -356,7 +356,7 @@ class StateObserverRollerShutter(_StateObserverBase):
}
# Items:
Rollershutter I_Rollershutter "Rollershutter [%s]" {channel="knx:device:bridge:T00_99_OpenHab_RollershutterObserver:Rollershutter"}
Rollershutter I_Rollershutter "Rollershutter" {channel="knx:device:bridge:T00_99_OpenHab_RollershutterObserver:Rollershutter"}
Rollershutter I_Rollershutter_ctr "Rollershutter ctr" {channel="knx:device:bridge:T00_99_OpenHab_RollershutterObserver:Rollershutter_ctr"}
Rollershutter I_Rollershutter_group "Rollershutter Group" {channel="knx:device:bridge:T00_99_OpenHab_RollershutterObserver:Rollershutter_group"}
Expand Down Expand Up @@ -439,7 +439,7 @@ class StateObserverNumber(_StateObserverBase):
}
# Items:
Number I01_01_Number "Switch [%s]" {channel="knx:device:bridge:T00_99_OpenHab_DimmerNumber:number"}
Number I01_01_Number "Switch" {channel="knx:device:bridge:T00_99_OpenHab_DimmerNumber:number"}
# Rule init:
habapp_rules.actors.state_observer.StateObserverNumber("I01_01_Number", callback_value_changed)
Expand Down
7 changes: 3 additions & 4 deletions habapp_rules/actors/ventilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import habapp_rules.core.logger
import habapp_rules.core.state_machine_rule
import habapp_rules.system
from habapp_rules import TIMEZONE

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,7 +69,7 @@ def __init__(self, config: habapp_rules.actors.config.ventilation.VentilationCon

# init state machine
self._previous_state = None
self._state_change_time = datetime.datetime.now(tz=TIMEZONE)
self._state_change_time = datetime.datetime.now()
self.state_machine = habapp_rules.core.state_machine_rule.HierarchicalStateMachineWithTimeout(model=self, states=self.states, transitions=self.trans, ignore_invalid_triggers=True, after_state_change="_update_openhab_state")
self._set_initial_state()

Expand Down Expand Up @@ -118,7 +117,7 @@ def _update_openhab_state(self) -> None:
"""
if self.state != self._previous_state:
super()._update_openhab_state()
self._state_change_time = datetime.datetime.now(tz=TIMEZONE)
self._state_change_time = datetime.datetime.now()
self._instance_logger.debug(f"State change: {self._previous_state} -> {self.state}")

self._set_level()
Expand Down Expand Up @@ -195,7 +194,7 @@ def __set_hand_display_text(self) -> None:
return

# get the remaining minutes and set display text
remaining_minutes = round((self._config.parameter.state_hand.timeout - (datetime.datetime.now(tz=TIMEZONE) - self._state_change_time).seconds) / 60)
remaining_minutes = round((self._config.parameter.state_hand.timeout - (datetime.datetime.now() - self._state_change_time).seconds) / 60)
remaining_minutes = max(remaining_minutes, 0)
habapp_rules.core.helper.send_if_different(self._config.items.display_text, f"{self._config.parameter.state_hand.display_text} {remaining_minutes}min")

Expand Down
Loading

0 comments on commit c7a79f1

Please sign in to comment.