Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24.02.0 #438

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/publish-dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ jobs:
environment: release

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: master

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
version: latest

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push release
id: docker_build_release
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
Expand All @@ -46,7 +46,7 @@ jobs:

- name: Build and push latest
id: docker_build_latest
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: master

- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/run-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.11'
- uses: pre-commit/[email protected]


Expand All @@ -23,9 +23,9 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-ast
- id: check-builtin-literals
Expand All @@ -22,7 +22,7 @@ repos:


- repo: https://github.com/PyCQA/flake8
rev: '6.1.0'
rev: '7.0.0'
hooks:
- id: flake8
# additional_dependencies:
Expand Down
6 changes: 5 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ src = ["src", "test"]
# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports
ignore-init-module-imports = true

extend-exclude = ["__init__.py"]
extend-exclude = [
"__init__.py",
"src/__test_*.py"
]

select = [
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
Expand Down Expand Up @@ -62,6 +65,7 @@ builtins-ignorelist = ["id", "input"]
[lint.per-file-ignores]
"docs/conf.py" = ["INP001", "A001"]
"setup.py" = ["PTH123"]
"run/**" = ["INP001"]


[lint.isort]
Expand Down
16 changes: 8 additions & 8 deletions docs/class_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,63 @@ Scheduler
OneTimeJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.OneTimeJob
.. autoclass:: HABApp.rule.scheduler.jobs.OneTimeJob
:members:
:inherited-members:
:member-order: groupwise

CountdownJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.CountdownJob
.. autoclass:: HABApp.rule.scheduler.jobs.CountdownJob
:members:
:inherited-members:
:member-order: groupwise

ReoccurringJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.ReoccurringJob
.. autoclass:: HABApp.rule.scheduler.jobs.ReoccurringJob
:members:
:inherited-members:
:member-order: groupwise

DayOfWeekJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.DayOfWeekJob
.. autoclass:: HABApp.rule.scheduler.jobs.DayOfWeekJob
:members:
:inherited-members:
:member-order: groupwise

DawnJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.DawnJob
.. autoclass:: HABApp.rule.scheduler.jobs.DawnJob
:members:
:inherited-members:
:member-order: groupwise

SunriseJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.SunriseJob
.. autoclass:: HABApp.rule.scheduler.jobs.SunriseJob
:members:
:inherited-members:
:member-order: groupwise

SunsetJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.SunsetJob
.. autoclass:: HABApp.rule.scheduler.jobs.SunsetJob
:members:
:inherited-members:
:member-order: groupwise

DuskJob
""""""""""""""""""""""""""""""""""""""

.. autoclass:: eascheduler.scheduler_view.DuskJob
.. autoclass:: HABApp.rule.scheduler.jobs.DuskJob
:members:
:inherited-members:
:member-order: groupwise
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from docutils.nodes import Node, Text
from sphinx.addnodes import desc_signature


IS_RTD_BUILD = os.environ.get('READTHEDOCS', '-').lower() == 'true'
IS_CI = os.environ.get('CI', '-') == 'true'

Expand Down Expand Up @@ -71,6 +72,7 @@ def log(msg: str):
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx_autodoc_typehints',
'sphinx_exec_code',
'sphinx.ext.inheritance_diagram',
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Example

mqtt:
connection:
client_id: HABApp
identifier: HABApp
host: ''
port: 8883
user: ''
Expand Down
2 changes: 1 addition & 1 deletion docs/interface_mqtt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ and it will also trigger for :class:`~HABApp.mqtt.events.MqttValueUpdateEvent`.
MqttValueChangeEvent
""""""""""""""""""""""""""""""""""""""
Since this event inherits from :class:`~HABApp.core.events.ValueChangeEvent` you can listen to :class:`~HABApp.core.events.ValueChangeEvent`
and it will also trigger for :class:`~HABApp.mqtt.events.MqttValueUpdateEvent`.
and it will also trigger for :class:`~HABApp.mqtt.events.MqttValueChangeEvent`.

.. inheritance-diagram:: HABApp.mqtt.events.MqttValueChangeEvent
:parts: 1
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Packages required to build the documentation
sphinx == 7.2.6
sphinx-autodoc-typehints == 1.25.2
sphinx-autodoc-typehints == 2.0.0
sphinx_rtd_theme == 2.0.0
sphinx-exec-code == 0.10
sphinx-exec-code == 0.12
autodoc_pydantic == 2.0.1
sphinx-copybutton == 0.5.2
23 changes: 20 additions & 3 deletions docs/rule_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ Turn a device off 30 seconds after one of the movement sensors in a room signals
Process Errors in Rules
------------------------------------------
This example shows how to create a rule with a function which will be called when **any** rule throws an error.
The rule function then can push the error message to an openHAB item or e.g. use Pushover to send the error message
to the mobile device (see :doc:`Advanced Usage <advanced_usage>` for more information).
The rule function then can push the error message to an openHAB item, use a notification service to send the error
message to the mobile device or send an email with the error message.
See :doc:`Advanced Usage <advanced_usage>` for more information about the available internal topics.
It also uses the built in :ref:`rate limiter <RATE_LIMITER>` to limit the amount of notifications.

.. exec_code::

Expand All @@ -130,6 +132,14 @@ to the mobile device (see :doc:`Advanced Usage <advanced_usage>` for more inform
import HABApp
from HABApp.core.events.habapp_events import HABAppException
from HABApp.core.events import EventFilter
from HABApp.util import RateLimiter


# Set up rate limiter to limit the amount of notifications
LIMITER = RateLimiter('MyNotifications')
LIMITER.parse_limits('5 in 1 minute', algorithm='fixed_window_elastic_expiry')
LIMITER.parse_limits("20 in 1 hour", algorithm='leaky_bucket')


class NotifyOnError(HABApp.Rule):
def __init__(self):
Expand All @@ -140,12 +150,19 @@ to the mobile device (see :doc:`Advanced Usage <advanced_usage>` for more inform

def on_error(self, error_event: HABAppException):
msg = error_event.to_str() if isinstance(error_event, HABAppException) else error_event

# use limiter
if not LIMITER.allow():
return None

# Replace this part with your notification logic
print('Error in rules:')
print(msg)

NotifyOnError()


# this is a faulty example. Do not create this part!
# this is a faulty rule as an example. Do not create this part!
class FaultyRule(HABApp.Rule):
def __init__(self):
super().__init__()
Expand Down
3 changes: 3 additions & 0 deletions docs/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Converts a hsb value to the rgb color space
.. autofunction:: HABApp.util.functions.hsb_to_rgb


.. _RATE_LIMITER:


Rate limiter
------------------------------
A simple rate limiter implementation which can be used in rules.
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ MyOpenhabRule()
```

# Changelog
#### 24.02.0 (2024-02-14)
- For openHAB >= 4.1 it's possible to wait for a minimum openHAB uptime before connecting (defaults to 60s)
- Renamed config entry mqtt.connection.client_id to identifier (backwards compatible)
- ``ItemTimeSeriesUpdatedEvent`` gets ignored
- Updated dependencies
- Updated docs

#### 24.01.0 (2024-01-08)
- Added HABApp.util.RateLimiter
- Added CompressedMidnightRotatingFileHandler
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Packages for source formatting
# -----------------------------------------------------------------------------
pre-commit == 3.5.0 # 3.6.0 requires python >= 3.10
ruff == 0.1.11
ruff == 0.2.1

# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
14 changes: 7 additions & 7 deletions requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
aiohttp == 3.9.1
pydantic == 2.5.3
msgspec == 0.18.5
aiohttp == 3.9.3
pydantic == 2.6.1
msgspec == 0.18.6
bidict == 0.22.1
watchdog == 3.0.0
watchdog == 4.0.0
ujson == 5.9.0
aiomqtt == 1.2.1
aiomqtt == 2.0.0

immutables == 0.20
eascheduler == 0.1.11
easyconfig == 0.3.1
easyconfig == 0.3.2
pendulum == 2.1.2
stack_data == 0.6.3
colorama == 0.4.6

voluptuous == 0.14.1
voluptuous == 0.14.2

typing-extensions == 4.9.0

Expand Down
2 changes: 1 addition & 1 deletion requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# -----------------------------------------------------------------------------
packaging == 23.2
pytest == 7.4.4
pytest-asyncio == 0.23.3
pytest-asyncio == 0.23.4
2 changes: 1 addition & 1 deletion run/conf/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ location:

mqtt:
connection:
client_id: HABAppConf
identifier: HABAppConf
host: localhost
password: ''
port: 1883
Expand Down
1 change: 1 addition & 0 deletions run/conf/rules/logging_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import HABApp


log = logging.getLogger('MyRule')


Expand Down
6 changes: 3 additions & 3 deletions run/conf/rules/openhab_rule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import HABApp
from HABApp.core.events import ValueUpdateEvent, ValueChangeEvent
from HABApp.openhab.events import ItemStateEvent, ItemCommandEvent, ItemStateChangedEvent
from HABApp.openhab.items import SwitchItem, ContactItem, DatetimeItem
from HABApp.core.events import ValueChangeEvent, ValueUpdateEvent
from HABApp.openhab.events import ItemCommandEvent, ItemStateChangedEvent, ItemStateEvent
from HABApp.openhab.items import ContactItem, DatetimeItem, SwitchItem


class MyOpenhabRule(HABApp.Rule):
Expand Down
2 changes: 1 addition & 1 deletion run/conf/rules/openhab_things.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from HABApp import Rule
from HABApp.core.events import EventFilter
from HABApp.openhab.events import ThingStatusInfoChangedEvent
from HABApp.openhab.items import Thing
from HABApp.core.events import EventFilter


class CheckAllThings(Rule):
Expand Down
2 changes: 1 addition & 1 deletion run/conf/rules/openhab_to_mqtt_rule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HABApp
from HABApp.openhab.events import ItemStateUpdatedEventFilter, ItemStateEvent
from HABApp.openhab.events import ItemStateEvent, ItemStateUpdatedEventFilter
from HABApp.openhab.items import OpenhabItem


Expand Down
Loading
Loading