Skip to content

Commit 610e73d

Browse files
committed
Move library dependecy to local _vendor folder so it will not mix with the core version.
1 parent 236d27f commit 610e73d

37 files changed

Lines changed: 8191 additions & 39 deletions

.github/scripts/merge_topics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def main():
4343
"MetricType.SPEED",
4444
"MetricType.LIQUID_VOLUME",
4545
"MetricType.DURATION",
46+
"MetricType.IRRADIANCE",
4647
}
4748

4849
# Update topics: add or update entries in en.json under entity.sensor for each topic id

.github/workflows/update_victron_mqtt.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ jobs:
3636
- name: Check if update is needed
3737
id: check_update
3838
run: |
39-
current=$(jq -r '.requirements[0]' custom_components/victron_mqtt/manifest.json | cut -d'=' -f3)
39+
# Compare against the vendored lib version by checking the wheel we'd download
4040
latest="${{ steps.get_release.outputs.latest_version }}"
41+
# Check if the lib/ directory already has this version by looking at a marker file
42+
if [ -f "custom_components/victron_mqtt/_vendor/victron_mqtt/.vendored_version" ]; then
43+
current=$(cat custom_components/victron_mqtt/_vendor/victron_mqtt/.vendored_version)
44+
else
45+
current="unknown"
46+
fi
4147
echo "Current: $current, Latest: $latest"
4248
if [ "$current" = "$latest" ]; then
4349
echo "No update needed."
@@ -47,20 +53,33 @@ jobs:
4753
echo "update_needed=true" >> $GITHUB_OUTPUT
4854
fi
4955
50-
- name: Update dependency pins with new version
56+
- name: Download and vendor victron_mqtt library
5157
if: steps.check_update.outputs.update_needed == 'true'
5258
run: |
5359
set -e
5460
latest="${{ steps.get_release.outputs.latest_version }}"
5561
56-
# Pin integration runtime dependency.
57-
jq \
58-
--arg v "$latest" \
59-
'.requirements[0] = "victron_mqtt=="+$v' \
60-
custom_components/victron_mqtt/manifest.json > manifest.tmp && mv manifest.tmp custom_components/victron_mqtt/manifest.json
62+
# Download the wheel from PyPI
63+
pip download "victron_mqtt==$latest" --no-deps -d /tmp/victron_wheel
64+
65+
# Extract the wheel (it's a zip file)
66+
wheel_file=$(ls /tmp/victron_wheel/victron_mqtt-*.whl)
67+
unzip -o "$wheel_file" "victron_mqtt/*" -d /tmp/victron_extracted
68+
69+
# Replace the vendored lib/ directory
70+
rm -rf custom_components/victron_mqtt/_vendor/victron_mqtt
71+
cp -r /tmp/victron_extracted/victron_mqtt custom_components/victron_mqtt/_vendor/victron_mqtt
72+
73+
# Remove __pycache__, py.typed, and utils/ (not needed in integration context)
74+
find custom_components/victron_mqtt/_vendor/victron_mqtt -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
75+
rm -f custom_components/victron_mqtt/_vendor/victron_mqtt/py.typed
76+
rm -rf custom_components/victron_mqtt/_vendor/victron_mqtt/utils
77+
78+
# Write version marker
79+
echo "$latest" > custom_components/victron_mqtt/_vendor/victron_mqtt/.vendored_version
6180
62-
# Pin local/dev test dependency.
63-
sed -i -E "s|^victron_mqtt(==[0-9][0-9A-Za-z.\-]*)?$|victron_mqtt==$latest|" requirements.txt
81+
# Cleanup
82+
rm -rf /tmp/victron_wheel /tmp/victron_extracted
6483
6584
- name: Download victron_mqtt release package from PyPI
6685
if: steps.check_update.outputs.update_needed == 'true'

custom_components/victron_mqtt/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""The victron_mqtt integration."""
22

3-
import asyncio
43
import importlib.metadata
54
import logging
65

@@ -66,16 +65,13 @@ async def handle_publish(call: ServiceCall) -> None:
6665
_LOGGER.info("Victron MQTT services registered")
6766

6867

69-
async def get_package_version(package_name: str) -> str:
70-
return await asyncio.get_event_loop().run_in_executor(
71-
None, importlib.metadata.version, package_name
72-
)
73-
74-
7568
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
7669
"""Set up the integration."""
7770
version = getattr(hass.data.get("integrations", {}).get(DOMAIN), "version", "unknown")
78-
victron_mqtt_version = await get_package_version("victron_mqtt")
71+
try:
72+
victron_mqtt_version = importlib.metadata.version("victron_mqtt")
73+
except importlib.metadata.PackageNotFoundError:
74+
victron_mqtt_version = "vendored"
7975
_LOGGER.info(
8076
"Setting up victron_mqtt integration. Version: %s. victron_mqtt package version: %s",
8177
version,

custom_components/victron_mqtt/_vendor/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026.5.7
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""
2+
A Asynchronous Python API client for the Victron Venus OS.
3+
"""
4+
5+
from ._victron_enums import (
6+
ACActiveInputSource,
7+
AcInputTypeEnum,
8+
ACSystemMode,
9+
ActiveInputEnum,
10+
BatteryState,
11+
ChargerMode,
12+
ChargeSchedule,
13+
DESSErrorCode,
14+
DESSMode,
15+
DESSReactiveStrategy,
16+
DESSRestrictions,
17+
DESSStrategy,
18+
DeviceType,
19+
DigitalInputInputState,
20+
DigitalInputState,
21+
DigitalInputType,
22+
ErrorCode,
23+
ESSMode,
24+
ESSModeHub4,
25+
ESSState,
26+
ESSUserMode,
27+
EvChargerMode,
28+
EvChargerPosition,
29+
EvChargerStatus,
30+
FluidType,
31+
GeneratorRunningByConditionCode,
32+
GenericAlarmEnum,
33+
GenericOnOff,
34+
InverterMode,
35+
MppOperationMode,
36+
PhoenixInverterMode,
37+
PreferRenewableEnergyEnum,
38+
SolarChargerDeviceOffReason,
39+
State,
40+
SwitchableOutputType,
41+
TemperatureStatus,
42+
TemperatureType,
43+
VictronDeviceEnum,
44+
)
45+
from .constants import MetricKind, MetricNature, MetricType, OperationMode, RangeType, VictronEnum
46+
from .data_classes import GpsLocation
47+
from .device import Device
48+
from .formula_metric import FormulaMetric
49+
from .hub import (
50+
AuthenticationError,
51+
CannotConnectError,
52+
Hub,
53+
InvalidInstallationIdError,
54+
NotConnectedError,
55+
ProgrammingError,
56+
TopicNotFoundError,
57+
)
58+
from .metric import Metric
59+
from .writable_metric import WritableMetric
60+
61+
__all__ = [
62+
"ACActiveInputSource",
63+
"ACSystemMode",
64+
"AcInputTypeEnum",
65+
"ActiveInputEnum",
66+
"AuthenticationError",
67+
"BatteryState",
68+
"CannotConnectError",
69+
"ChargeSchedule",
70+
"ChargerMode",
71+
"DESSErrorCode",
72+
"DESSMode",
73+
"DESSReactiveStrategy",
74+
"DESSRestrictions",
75+
"DESSStrategy",
76+
"Device",
77+
"DeviceType",
78+
"DigitalInputInputState",
79+
"DigitalInputState",
80+
"DigitalInputType",
81+
"ESSMode",
82+
"ESSModeHub4",
83+
"ESSState",
84+
"ESSUserMode",
85+
"ErrorCode",
86+
"EvChargerMode",
87+
"EvChargerPosition",
88+
"EvChargerStatus",
89+
"FluidType",
90+
"FormulaMetric",
91+
"GeneratorRunningByConditionCode",
92+
"GenericAlarmEnum",
93+
"GenericOnOff",
94+
"GpsLocation",
95+
"Hub",
96+
"InvalidInstallationIdError",
97+
"InverterMode",
98+
"Metric",
99+
"MetricKind",
100+
"MetricNature",
101+
"MetricType",
102+
"MppOperationMode",
103+
"NotConnectedError",
104+
"OperationMode",
105+
"PhoenixInverterMode",
106+
"PreferRenewableEnergyEnum",
107+
"ProgrammingError",
108+
"RangeType",
109+
"SolarChargerDeviceOffReason",
110+
"State",
111+
"SwitchableOutputType",
112+
"TemperatureStatus",
113+
"TemperatureType",
114+
"TopicNotFoundError",
115+
"VictronDeviceEnum",
116+
"VictronEnum",
117+
"WritableMetric",
118+
]

0 commit comments

Comments
 (0)