hydroqc2mqtt now works in this setup. had to patch it for aiomqtt 2.0.0
This commit is contained in:
parent
4fadb21402
commit
bad3bf1682
2
acct-group/hydroqc2mqtt/Manifest
Normal file
2
acct-group/hydroqc2mqtt/Manifest
Normal file
@ -0,0 +1,2 @@
|
||||
EBUILD hydroqc2mqtt-0.ebuild 149 BLAKE2B 3d48d41dbcf9acdfda3e3d81fefd5767aea861faeef65ea5b95caa414160e340303e9788f1444b2d1d9b7631d6d6d461b7aca2558b3f69b7bb26c893f73ca24c SHA512 5dd40eea1228c17d97955b872eec9d63cf4a3b80d19da23db6de9b8f566e1eb91e5495b98eaceaa18115af92ae1a0e354a09df1fa8d5c5642fd14b8cb35c3e87
|
||||
MISC metadata.xml 397 BLAKE2B 77f11f2779e3c2147c1eabcd034c7a07fd32c004cfd8363104956e10ef3f2381a710aef0152e4ed6a598c9065aa0a7b2c3f63f739c67dcde061527a4bf030679 SHA512 5e0bcf6f8de4434343b44a0a4898184e933b1a069b31bffb58e16aab438a1937d2c7707f0afed50c7efd0f55d5633e26738e294c58ff44452b4dd1ede006ec91
|
7
acct-group/hydroqc2mqtt/hydroqc2mqtt-0.ebuild
Normal file
7
acct-group/hydroqc2mqtt/hydroqc2mqtt-0.ebuild
Normal file
@ -0,0 +1,7 @@
|
||||
# Copyright 1999-2023 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
EAPI=7
|
||||
|
||||
inherit acct-group
|
||||
ACCT_GROUP_ID=-1
|
12
acct-group/hydroqc2mqtt/metadata.xml
Normal file
12
acct-group/hydroqc2mqtt/metadata.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
|
||||
<pkgmetadata>
|
||||
<maintainer type="person" proxied="yes">
|
||||
<email>web@inode64.com</email>
|
||||
<name>Fco. Javier Félix</name>
|
||||
</maintainer>
|
||||
<maintainer type="project" proxied="proxy">
|
||||
<email>proxy-maint@gentoo.org</email>
|
||||
<name>Proxy Maintainers</name>
|
||||
</maintainer>
|
||||
</pkgmetadata>
|
2
acct-user/hydroqc2mqtt/Manifest
Normal file
2
acct-user/hydroqc2mqtt/Manifest
Normal file
@ -0,0 +1,2 @@
|
||||
EBUILD hydroqc2mqtt-0.ebuild 234 BLAKE2B 3ceee4a6be60a29c575bc66128a7d1d5c456ef93cd0725b499c15eaf2c3079b3cff5266a64f2c01f19749b03606b30854e64d90ec39a474eb28c0c0ffbd1d916 SHA512 1818a3a60f1213efd929c892fd794f79ff090d4bf870b770deb75f06edab4898c08f865b2b0242421e679302534bc56d87d8eb5b8182d74ce37ee287ef920e84
|
||||
MISC metadata.xml 397 BLAKE2B 77f11f2779e3c2147c1eabcd034c7a07fd32c004cfd8363104956e10ef3f2381a710aef0152e4ed6a598c9065aa0a7b2c3f63f739c67dcde061527a4bf030679 SHA512 5e0bcf6f8de4434343b44a0a4898184e933b1a069b31bffb58e16aab438a1937d2c7707f0afed50c7efd0f55d5633e26738e294c58ff44452b4dd1ede006ec91
|
12
acct-user/hydroqc2mqtt/hydroqc2mqtt-0.ebuild
Normal file
12
acct-user/hydroqc2mqtt/hydroqc2mqtt-0.ebuild
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright 1999-2023 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
EAPI=7
|
||||
|
||||
inherit acct-user
|
||||
|
||||
DESCRIPTION="A user for ${PN}"
|
||||
ACCT_USER_GROUPS=( ${PN} dialout )
|
||||
ACCT_USER_ID=-1
|
||||
|
||||
acct-user_add_deps
|
12
acct-user/hydroqc2mqtt/metadata.xml
Normal file
12
acct-user/hydroqc2mqtt/metadata.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
|
||||
<pkgmetadata>
|
||||
<maintainer type="person" proxied="yes">
|
||||
<email>web@inode64.com</email>
|
||||
<name>Fco. Javier Félix</name>
|
||||
</maintainer>
|
||||
<maintainer type="project" proxied="proxy">
|
||||
<email>proxy-maint@gentoo.org</email>
|
||||
<name>Proxy Maintainers</name>
|
||||
</maintainer>
|
||||
</pkgmetadata>
|
@ -1,2 +1,4 @@
|
||||
AUX hydroqc2mqtt 683 BLAKE2B 14103c1ff776944327d60867cad15790cd37facd1bf728efb7aa75dabe7d83db5290d552a8afc53634f5343476422f4d66b854984041b6a12edf030e9a222bd2 SHA512 58e089e0d3829a1b8add59d26d090c1f63fa500ce87a535cc8226711061929e23bcd82fe7d349acaad18ba84c28c0de99eec940e0c5568cf143d3078b71de938
|
||||
AUX hydroqc2mqtt.service 745 BLAKE2B 5b03c97ad51b4769b166da387dbd17d1a35ce58b981b451d7cdbaeed9f789be5bfba31945dd08d91de8802dae1ce4c85f165e072765f4b0ac47a36a4e9f95fa6 SHA512 4a52301c9ab0e8cffcc565131f0c999ac3dd6b6a4ec0f702ea8a1b42abf886d796091559ce3b57c839e50f45bd12a195b715d2ffa4a6955fa8f3bbe92a7383a3
|
||||
DIST hydroqc2mqtt-1.3.0.tar.gz 65031 BLAKE2B 0ad48574364cb07ad82f9953b9f648528c25c098c3a2cfa723af3e17e8d9f63d2bc9a9abaa2160d2cc53031c7ca10fe9d4f17035a85da7f94f0134e761050806 SHA512 5fd519dbb049839f24c7589e2d6ffe5d00d0d0b2582375295d1308e2ffbf8139dbc41fe73c0bf74b9fe59f09b0ba4ca6f34ff471d071dcf146f3cdf3f51bbac7
|
||||
EBUILD hydroqc2mqtt-1.3.0.ebuild 1656 BLAKE2B 310b45ff097d7f3626038f9e11edff8e3437714342878490bd317f2ae01da938b5f29b2962e8e594af1fd1144306d5fc1dfba714f67f9c4c240f2078ef7b452c SHA512 c9e413cbe38907fa097afb671781867eb3366cbcb7e8acefa3121c4c5469c6a05078087fdc19c25b33605f0b4803852b08b8edbaaa65651bd5d9233f718a1c0c
|
||||
EBUILD hydroqc2mqtt-1.3.0.ebuild 2024 BLAKE2B 81556773046e704cf733bf6b9326239ca1dd85f430b3ec35d1824c698737fe147b95f4a67c0a44dfa5ced91e245258a8aa8e90e7f43decda258e396e65d2806f SHA512 06d383df1c702c2295a96630591fa877b0c5166f1647243d7b39c8ec9634660e451be9fde85dc99c3bd5ad26f84508326e48bf52004a2ff84eba3596ddf4f91e
|
||||
|
28
dev-python/hydroqc2mqtt/files/hydroqc2mqtt
Normal file
28
dev-python/hydroqc2mqtt/files/hydroqc2mqtt
Normal file
@ -0,0 +1,28 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
retry="30"
|
||||
|
||||
depend() {
|
||||
after mosquitto
|
||||
}
|
||||
|
||||
checkconfig() {
|
||||
if [ ! -f "/etc/${SVCNAME}/config.yaml" ] ; then
|
||||
eerror "File '/etc/${SVCNAME}/config.yaml' does not exist!"
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
checkconfig || return 1
|
||||
ebegin "Starting ${SVCNAME}"
|
||||
start-stop-daemon --start --user hydroqc2mqtt:hydroqc2mqtt --exec /usr/bin/hydroqc2mqtt --background \
|
||||
--make-pidfile --pidfile /run/${SVCNAME}.pid --stdout /var/log/${SVCNAME}/${SVCNAME}.log --stderr /var/log/${SVCNAME}/${SVCNAME}.err \
|
||||
-- --config /etc/${SVCNAME}/config.yaml
|
||||
eend $?
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping ${SVCNAME}"
|
||||
start-stop-daemon --stop --quiet --retry 10 --pidfile /run/${SVCNAME}.pid
|
||||
eend $?
|
||||
}
|
40
dev-python/hydroqc2mqtt/files/hydroqc2mqtt.service
Normal file
40
dev-python/hydroqc2mqtt/files/hydroqc2mqtt.service
Normal file
@ -0,0 +1,40 @@
|
||||
[Unit]
|
||||
Description=hydroqc2mqtt
|
||||
After=network.target
|
||||
Wants=mosquitto.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/hydroqc2mqtt
|
||||
StandardOutput=inherit
|
||||
StandardError=inherit
|
||||
Restart=always
|
||||
User=hydroqc2mqtt
|
||||
|
||||
CapabilityBoundingSet=
|
||||
NoNewPrivileges=true
|
||||
RemoveIPC=true
|
||||
LockPersonality=true
|
||||
|
||||
ProtectControlGroups=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectHostname=true
|
||||
ProtectProc=noaccess
|
||||
ProtectClock=yes
|
||||
DeviceAllow=char-* rw
|
||||
|
||||
RestrictRealtime=true
|
||||
RestrictSUIDSGID=true
|
||||
RestrictNamespaces=true
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
||||
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
PrivateTmp=true
|
||||
|
||||
SystemCallArchitectures=native
|
||||
SystemCallFilter=@system-service @pkey
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -5,7 +5,7 @@ EAPI=8
|
||||
|
||||
PYTHON_COMPAT=( python3_{11..13} )
|
||||
DISTUTILS_USE_PEP517=setuptools
|
||||
inherit distutils-r1 pypi
|
||||
inherit distutils-r1 pypi systemd
|
||||
|
||||
DESCRIPTION="MQTT daemon that sends your Hydro-Quebec account information to your MQTT server for consumption by Home-Assistant or other home automation platforms."
|
||||
HOMEPAGE="https://hydroqc.ca/en/ https://gitlab.com/hydroqc/hydroqc2mqtt https://pypi.org/project/hydroqc2mqtt/"
|
||||
@ -13,12 +13,13 @@ HOMEPAGE="https://hydroqc.ca/en/ https://gitlab.com/hydroqc/hydroqc2mqtt https:/
|
||||
LICENSE="AGPL-3"
|
||||
SLOT="0"
|
||||
KEYWORDS="amd64 arm arm64 x86"
|
||||
IUSE="+ujson" # "test"
|
||||
#RESTRICT="!test? ( test )"
|
||||
IUSE="+ujson"
|
||||
|
||||
DOCS="README.md"
|
||||
|
||||
RDEPEND="
|
||||
acct-user/hydroqc2mqtt
|
||||
acct-group/hydroqc2mqtt
|
||||
dev-python/hydroqc[${PYTHON_USEDEP}]
|
||||
dev-python/mqtt_hass_base[${PYTHON_USEDEP}]
|
||||
dev-python/aiohttp[${PYTHON_USEDEP}]
|
||||
@ -29,6 +30,7 @@ RDEPEND="
|
||||
dev-python/python-dateutil[${PYTHON_USEDEP}]
|
||||
dev-python/pytz[${PYTHON_USEDEP}]
|
||||
|| ( app-misc/homeassistant-min[mqtt,${PYTHON_USEDEP}] app-misc/homeassistant[mqtt,${PYTHON_USEDEP}] app-misc/homeassistant-full[mqtt,${PYTHON_USEDEP}] )
|
||||
dev-python/msgpack[${PYTHON_USEDEP}]
|
||||
"
|
||||
|
||||
#BDEPEND="
|
||||
@ -40,11 +42,28 @@ RDEPEND="
|
||||
# dev-python/pytest-timeout[${PYTHON_USEDEP}]
|
||||
# )"
|
||||
|
||||
distutils_enable_tests pytest
|
||||
|
||||
src_prepare() {
|
||||
# remove dynamic stuff and force version
|
||||
sed 's/dynamic = \[.*\]/version = \"'${PV}'\"/g' -i pyproject.toml || die
|
||||
sed 's/, "setuptools-git-versioning<2"//g' -i pyproject.toml || die
|
||||
eapply_user
|
||||
|
||||
distutils-r1_src_prepare
|
||||
}
|
||||
|
||||
src_install() {
|
||||
keepdir "/var/log/${PN}"
|
||||
fowners -R ${PN}:${PN} "/var/log/${PN}"
|
||||
|
||||
keepdir "/etc/${PN}"
|
||||
insinto "/etc/${PN}"
|
||||
doins config.sample.yaml
|
||||
fowners -R ${PN}:${PN} "/etc/${PN}"
|
||||
|
||||
doinitd "${FILESDIR}"/${PN}
|
||||
systemd_dounit "${FILESDIR}/${PN}.service"
|
||||
|
||||
distutils-r1_src_install
|
||||
}
|
||||
|
||||
distutils_enable_tests pytest
|
||||
|
@ -1,2 +1,3 @@
|
||||
AUX mqtt_hass_base-aiomqtt-2.0.0.patch 13589 BLAKE2B 0e51afd79b2d130814ac70e1d93abd9be042add627a333b7026e3486f4d5d9282cbefa154bce9eb5049c8d91646d7221e165d4abc2c859aacc0b82351cfb4de2 SHA512 e3986881242811ffaee3a0a14cd3737ba8892817a49f78cd212a62eac82696ec45a406a120b19d5bfba47b79b136cb18d8d449e1c1e8a22cc2e3599f1b9f875c
|
||||
DIST mqtt_hass_base-4.3.0.tar.gz 65845 BLAKE2B 7ff81787295eee0130ffb69bd69e58082cdad52670b506a176256e0c76a66156f031937bc0c48dfb0bac5ffeb05a3c2b733f028d3bf2feb3139e90793cec498d SHA512 5ec0cbb2819fbe79d8656237454edd5a021c69a626687f72d51348110b10a02c9c08239c37b1ff5f50da4d79dccf33e4b8759c65765b662c279ba2e3261c8d78
|
||||
EBUILD mqtt_hass_base-4.3.0.ebuild 1292 BLAKE2B 0ee7e71982b8480bbd30635287982774fcced6efc33bb091e5699fbcd57e6510fb903c19ab0361156bb8f807946909c6bdee0f2f469e9a36a475f856564f481c SHA512 4aa7f12cf8953d4ce9df6fce8e67b535af2f1311e18e9041bca9a419cecd10182054fcf750ad8a127882d0c3c7e4545921755a7b47c43268b1683703b2989b52
|
||||
EBUILD mqtt_hass_base-4.3.0.ebuild 1356 BLAKE2B ca07486584b2226ce73cdfe69f2c62e89e0fdc5313aa7e382316cb81ce5f6872760aed5ae2d89f269a795f95df12041512cae87d37c29b698d18162024c50174 SHA512 2b552ff8e04fcdb8abf9061ade1f87fcc7c5d2bf098b749d012ea060089f7b1712393127acd2dc14502d1d2466fe69061e6f3df93ec7ecfa3db29471eafcc965
|
||||
|
@ -0,0 +1,332 @@
|
||||
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
|
||||
index 811dda7..00b0104 100644
|
||||
--- a/.pre-commit-config.yaml
|
||||
+++ b/.pre-commit-config.yaml
|
||||
@@ -39,7 +39,7 @@ repos:
|
||||
- id: mypy
|
||||
args: [--strict, --pretty, --show-error-codes]
|
||||
additional_dependencies:
|
||||
- - "aiomqtt==1.2.1"
|
||||
+ - "aiomqtt==2.0.0"
|
||||
- "pytest-asyncio==0.23.6"
|
||||
- "types-paho-mqtt==1.6.0.20240321"
|
||||
- - "homeassistant-stubs==2024.5.2"
|
||||
+ - "homeassistant-stubs==2024.10.4"
|
||||
diff --git a/mqtt_hass_base/daemon.py b/mqtt_hass_base/daemon.py
|
||||
index e3c73dc..d4b9af5 100644
|
||||
--- a/mqtt_hass_base/daemon.py
|
||||
+++ b/mqtt_hass_base/daemon.py
|
||||
@@ -127,7 +127,7 @@ class MqttClientDaemon:
|
||||
self.logger.setLevel(getattr(logging, self.log_level.upper()))
|
||||
|
||||
async def _mqtt_connect(self, stack: AsyncExitStack) -> None:
|
||||
- """Connecto to the MQTT server."""
|
||||
+ """Connect to the MQTT server."""
|
||||
self.logger.info("Connecting to MQTT server")
|
||||
tls_params = None
|
||||
if self._mqtt_ssl_enabled:
|
||||
@@ -142,7 +142,7 @@ class MqttClientDaemon:
|
||||
port=self.mqtt_port,
|
||||
# logger==
|
||||
keepalive=60,
|
||||
- client_id=self.name,
|
||||
+ identifier=self.name,
|
||||
username=self.mqtt_username,
|
||||
password=self.mqtt_password,
|
||||
transport=self._mqtt_transport,
|
||||
@@ -215,7 +215,6 @@ class MqttClientDaemon:
|
||||
self.logger.info("Main loop stopped")
|
||||
await self._loop_stopped()
|
||||
self.logger.info("Closing MQTT client")
|
||||
- await self.mqtt_client.disconnect(timeout=10)
|
||||
await self._base_on_disconnect()
|
||||
else:
|
||||
self.logger.info("Main loop never started")
|
||||
diff --git a/mqtt_hass_base/device.py b/mqtt_hass_base/device.py
|
||||
index dfab48c..4eb7f5c 100644
|
||||
--- a/mqtt_hass_base/device.py
|
||||
+++ b/mqtt_hass_base/device.py
|
||||
@@ -235,7 +235,7 @@ class MqttDevice:
|
||||
self._connections[raw_item[0]] = raw_item[1]
|
||||
else:
|
||||
raise MQTTHassBaseError(
|
||||
- f"Bad connection value: {raw_item} - Shoube dict or tuple"
|
||||
+ f"Bad connection value: {raw_item} - Should be dict or tuple"
|
||||
)
|
||||
|
||||
@property
|
||||
diff --git a/mqtt_hass_base/entity/button.py b/mqtt_hass_base/entity/button.py
|
||||
index a017b63..e08f59d 100644
|
||||
--- a/mqtt_hass_base/entity/button.py
|
||||
+++ b/mqtt_hass_base/entity/button.py
|
||||
@@ -99,12 +99,7 @@ class MqttButton(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if on_command_callback := self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, on_command_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/mqtt_hass_base/entity/common.py b/mqtt_hass_base/entity/common.py
|
||||
index 297474a..e874e3b 100644
|
||||
--- a/mqtt_hass_base/entity/common.py
|
||||
+++ b/mqtt_hass_base/entity/common.py
|
||||
@@ -3,12 +3,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
-from collections.abc import AsyncGenerator, Callable
|
||||
+from collections.abc import Callable
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Any, TypedDict
|
||||
|
||||
import aiomqtt as mqtt
|
||||
-import paho.mqtt.client as paho
|
||||
|
||||
from mqtt_hass_base.error import MQTTHassBaseError
|
||||
|
||||
@@ -158,12 +157,11 @@ class MqttEntity:
|
||||
|
||||
async def _on_messages(
|
||||
self,
|
||||
- messages: AsyncGenerator[paho.MQTTMessage, None],
|
||||
on_message_callback: Callable[..., Any],
|
||||
) -> None:
|
||||
"""on_command MQTT callback."""
|
||||
try:
|
||||
- async for message in messages:
|
||||
+ async for message in self._mqtt_client.messages:
|
||||
await on_message_callback(message)
|
||||
except mqtt.MqttError as exp:
|
||||
self.logger.warning(exp)
|
||||
diff --git a/mqtt_hass_base/entity/light.py b/mqtt_hass_base/entity/light.py
|
||||
index 1fdb9b0..18e1c69 100644
|
||||
--- a/mqtt_hass_base/entity/light.py
|
||||
+++ b/mqtt_hass_base/entity/light.py
|
||||
@@ -154,12 +154,7 @@ class MqttLight(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if on_command_callback := self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, on_command_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/mqtt_hass_base/entity/lock.py b/mqtt_hass_base/entity/lock.py
|
||||
index 990bb62..4a9cb17 100644
|
||||
--- a/mqtt_hass_base/entity/lock.py
|
||||
+++ b/mqtt_hass_base/entity/lock.py
|
||||
@@ -113,12 +113,7 @@ class MqttLock(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if on_command_callback := self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, on_command_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/mqtt_hass_base/entity/number.py b/mqtt_hass_base/entity/number.py
|
||||
index 0ae97cf..37031eb 100644
|
||||
--- a/mqtt_hass_base/entity/number.py
|
||||
+++ b/mqtt_hass_base/entity/number.py
|
||||
@@ -139,14 +139,7 @@ class MqttNumber(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(
|
||||
- self._on_messages(messages, self._set_current_value)
|
||||
- )
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(self._set_current_value)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/mqtt_hass_base/entity/switch.py b/mqtt_hass_base/entity/switch.py
|
||||
index ff115f6..50ea1a1 100644
|
||||
--- a/mqtt_hass_base/entity/switch.py
|
||||
+++ b/mqtt_hass_base/entity/switch.py
|
||||
@@ -112,12 +112,7 @@ class MqttSwitch(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if on_command_callback := self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, on_command_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/mqtt_hass_base/entity/vacuum.py b/mqtt_hass_base/entity/vacuum.py
|
||||
index e9fae38..1decfae 100644
|
||||
--- a/mqtt_hass_base/entity/vacuum.py
|
||||
+++ b/mqtt_hass_base/entity/vacuum.py
|
||||
@@ -148,38 +148,21 @@ class MqttVacuum(MqttEntity):
|
||||
"""Subscribe to all mqtt topics needed."""
|
||||
tasks: set[asyncio.Task[None]] = set()
|
||||
if on_command_callback := self._subscriptions.get("command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, on_command_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
await self._mqtt_client.subscribe(self.command_topic)
|
||||
|
||||
if on_send_command_callback := self._subscriptions.get("send_command_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.send_command_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(
|
||||
- self._on_messages(messages, on_send_command_callback)
|
||||
- )
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(on_send_command_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
await self._mqtt_client.subscribe(self.send_command_topic)
|
||||
|
||||
if set_fan_speed_callback := self._subscriptions.get("set_fan_speed_topic"):
|
||||
- messages = await stack.enter_async_context(
|
||||
- self._mqtt_client.filtered_messages(self.set_fan_speed_topic)
|
||||
- )
|
||||
- tasks.add(
|
||||
- asyncio.create_task(self._on_messages(messages, set_fan_speed_callback))
|
||||
- )
|
||||
+ tasks.add(asyncio.create_task(self._on_messages(set_fan_speed_callback)))
|
||||
# Subscribe to topic(s)
|
||||
# 🤔 Note that we subscribe *after* starting the message
|
||||
# loggers. Otherwise, we may miss retained messages.
|
||||
diff --git a/setup.cfg.old b/setup.cfg
|
||||
index 078d280..3458d39 100644
|
||||
--- a/setup.cfg.old
|
||||
+++ b/setup.cfg
|
||||
@@ -3,8 +3,8 @@ url = https://gitlab.com/ttblt-oss/hass/mqtt-hass-base
|
||||
|
||||
[options]
|
||||
install_requires =
|
||||
- homeassistant==2024.5.2
|
||||
- aiomqtt==1.2.1
|
||||
+ homeassistant==2024.10.4
|
||||
+ aiomqtt==2.0.0
|
||||
|
||||
[egg_info]
|
||||
tag_build =
|
||||
diff --git a/test_requirements.txt b/test_requirements.txt
|
||||
index 34fb6fe..68e988b 100644
|
||||
--- a/test_requirements.txt
|
||||
+++ b/test_requirements.txt
|
||||
@@ -4,10 +4,11 @@ pylint==3.1.0
|
||||
pytest==8.2.0
|
||||
pytest-cov==5.0.0
|
||||
pytest-asyncio==0.23.6
|
||||
-asyncio_mqtt==0.16.2
|
||||
+asyncio-mqtt==0.16.2
|
||||
black==24.4.2
|
||||
mypy==1.10.0
|
||||
pyright==1.1.362
|
||||
lxml==5.2.1
|
||||
types-paho-mqtt==1.6.0.20240321
|
||||
-homeassistant-stubs==2024.5.2
|
||||
+aiomqtt==2.0.0
|
||||
+homeassistant-stubs==2024.10.4
|
||||
diff --git a/tests/__init__.py b/tests/__init__.py
|
||||
new file mode 100644
|
||||
index 0000000..914c099
|
||||
--- /dev/null
|
||||
+++ b/tests/__init__.py
|
||||
@@ -0,0 +1 @@
|
||||
+"""MQTT Hass tests."""
|
||||
diff --git a/tests/test_daemon.py b/tests/test_daemon.py
|
||||
index 5ff2f6f..b8b78fa 100644
|
||||
--- a/tests/test_daemon.py
|
||||
+++ b/tests/test_daemon.py
|
||||
@@ -6,12 +6,11 @@ import os
|
||||
import signal
|
||||
import threading
|
||||
import traceback
|
||||
-from collections.abc import AsyncGenerator, Callable
|
||||
+from collections.abc import Callable
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Any
|
||||
|
||||
import aiomqtt as mqtt
|
||||
-import paho.mqtt.client as paho
|
||||
import pytest
|
||||
|
||||
from mqtt_hass_base.daemon import MqttClientDaemon
|
||||
@@ -65,22 +64,15 @@ def get_fakedaemon(
|
||||
test_fake_daemon._init_main_loop = _init_main_loop # type: ignore[method-assign]
|
||||
if test_step >= 7:
|
||||
|
||||
- async def on_messages(
|
||||
- messages: AsyncGenerator[ # pylint: disable=unused-argument
|
||||
- paho.MQTTMessage, None
|
||||
- ]
|
||||
- ) -> None:
|
||||
+ async def on_messages() -> None:
|
||||
pass
|
||||
|
||||
async def _main_loop( # pylint: disable=unused-argument,invalid-name
|
||||
self: MqttClientDaemon,
|
||||
stack: AsyncExitStack,
|
||||
) -> None:
|
||||
- messages = await stack.enter_async_context(
|
||||
- self.mqtt_client.unfiltered_messages()
|
||||
- )
|
||||
|
||||
- task = asyncio.create_task(on_messages(messages))
|
||||
+ task = asyncio.create_task(on_messages())
|
||||
self.tasks.add(task)
|
||||
await asyncio.gather(*self.tasks)
|
||||
self.must_run = False
|
||||
@@ -327,7 +319,7 @@ class TestBase:
|
||||
stack: AsyncExitStack, # pylint: disable=unused-argument
|
||||
) -> None:
|
||||
self.must_run = False
|
||||
- await self.mqtt_client.disconnect()
|
||||
+ await self.mqtt_client.__aexit__(None, None, None)
|
||||
await self.mqtt_client.publish("toto", "toto")
|
||||
|
||||
test_mqtt_daemon = get_fakedaemon(
|
||||
diff --git a/tests/test_device.py b/tests/test_device.py
|
||||
index 66d69bb..c462d70 100644
|
||||
--- a/tests/test_device.py
|
||||
+++ b/tests/test_device.py
|
||||
@@ -30,7 +30,7 @@ class TestBase:
|
||||
port=1883,
|
||||
# logger==
|
||||
keepalive=60,
|
||||
- client_id="fake_client",
|
||||
+ identifier="fake_client",
|
||||
username="hass",
|
||||
password="hass",
|
||||
)
|
@ -33,11 +33,13 @@ RDEPEND="
|
||||
# dev-python/pytest-timeout[${PYTHON_USEDEP}]
|
||||
# )"
|
||||
|
||||
PATCHES=("${FILESDIR}/${PN}-aiomqtt-2.0.0.patch")
|
||||
|
||||
src_prepare() {
|
||||
# remove dynamic stuff and force version
|
||||
sed 's/dynamic = \[.*\]/version = \"'${PV}'\"/g' -i pyproject.toml || die
|
||||
sed 's/, "setuptools-git-versioning<2"//g' -i pyproject.toml || die
|
||||
eapply_user
|
||||
distutils-r1_src_prepare
|
||||
}
|
||||
|
||||
distutils_enable_tests pytest
|
||||
|
Loading…
x
Reference in New Issue
Block a user