Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Oct 18, 2024
1 parent 9ce7436 commit b59e3da
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.0
hooks:
- id: ruff
name: ruff unused imports
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 == 4.0.1
ruff == 0.6.9
ruff == 0.7.0
autotyping == 24.9.0
# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
21 changes: 9 additions & 12 deletions src/HABApp/config/models/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import random
import string
from collections.abc import Generator
from pathlib import Path
from typing import Literal

Expand Down Expand Up @@ -42,18 +43,14 @@ def _migrate_client_id(cls, data):

class Subscribe(BaseModel):
qos: QOS = Field(default=0, description='Default QoS for subscribing')
topics: tuple[tuple[str, QOS | None], ...] = Field(default=('#', ))

@pydantic.field_validator('topics', mode='before')
def parse_topics(cls, v):
if not isinstance(v, (list, tuple, set)):
raise ValueError('must be a list')
ret = []
for e in v:
if isinstance(e, str):
e = (e, None)
ret.append(tuple(e))
return tuple(ret)
topics: tuple[str | tuple[str, QOS], ...] = Field(default=('#', 'topic/with/default/qos', ('topic/with/qos', 1)))

def get_topic_qos(self) -> Generator[tuple[str, QOS], None, None]:
for obj in self.topics:
if isinstance(obj, str):
yield obj, self.qos
else:
yield obj


class Publish(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions src/HABApp/mqtt/connection/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ async def apply_subscriptions(self) -> None:
# Unsubscribing has the corresponding handling, so we call that every time
if not self.plugin_connection.has_errors:
# subscription from config
for topic, qos in CONFIG.mqtt.subscribe.topics:
target[topic] = qos if qos is not None else default_qos
for topic, qos in CONFIG.mqtt.subscribe.get_topic_qos():
target[topic] = qos
# runtime subscriptions overwrite the subscriptions from the config file
for topic, qos in self.runtime_subs.items():
target[topic] = qos
Expand Down
6 changes: 4 additions & 2 deletions tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def test_default_file() -> None:
subscribe:
qos: 0 # Default QoS for subscribing
topics:
- - '#'
-
- '#'
- topic/with/default/qos
- - topic/with/qos
- 1
publish:
qos: 0 # Default QoS when publishing values
retain: false # Default retain flag when publishing values
Expand Down

0 comments on commit b59e3da

Please sign in to comment.