Skip to content

Commit

Permalink
Vendor pymodbus, rather than relying on the version which HA installs
Browse files Browse the repository at this point in the history
This should protect us from HA breaking things in the future!

Fixes: nathanmarlor#748
  • Loading branch information
canton7 committed Jan 31, 2025
1 parent e9d0178 commit 8b7f87d
Show file tree
Hide file tree
Showing 88 changed files with 13,801 additions and 29 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
Expand Down
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
require_serial: true
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tests/__snapshots__
custom_components/foxess_modbus/vendor
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter"
}
},
"python.analysis.extraPaths": [
"./custom_components/foxess_modbus/vendor/pymodbus/pymodbus-3.7.4"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Any
from typing import cast

from pymodbus.client import ModbusTcpClient
from pymodbus.exceptions import ConnectionException
from ..vendor.pymodbus import ConnectionException
from ..vendor.pymodbus import ModbusTcpClient

_LOGGER = logging.getLogger(__name__)

Expand Down
16 changes: 8 additions & 8 deletions custom_components/foxess_modbus/client/modbus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

import serial
from homeassistant.core import HomeAssistant
from pymodbus.client import ModbusSerialClient
from pymodbus.client import ModbusUdpClient
from pymodbus.framer import FramerType
from pymodbus.pdu import ModbusPDU
from pymodbus.pdu.register_read_message import ReadHoldingRegistersResponse
from pymodbus.pdu.register_read_message import ReadInputRegistersResponse
from pymodbus.pdu.register_write_message import WriteMultipleRegistersResponse
from pymodbus.pdu.register_write_message import WriteSingleRegisterResponse

from .. import client
from ..common.types import ConnectionType
Expand All @@ -28,6 +20,14 @@
from ..const import TCP
from ..const import UDP
from ..inverter_adapters import InverterAdapter
from ..vendor.pymodbus import FramerType
from ..vendor.pymodbus import ModbusPDU
from ..vendor.pymodbus import ModbusSerialClient
from ..vendor.pymodbus import ModbusUdpClient
from ..vendor.pymodbus import ReadHoldingRegistersResponse
from ..vendor.pymodbus import ReadInputRegistersResponse
from ..vendor.pymodbus import WriteMultipleRegistersResponse
from ..vendor.pymodbus import WriteSingleRegisterResponse
from .custom_modbus_tcp_client import CustomModbusTcpClient

_LOGGER = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/foxess_modbus/flow/adapter_flow_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.selector import selector
from pymodbus.exceptions import ConnectionException
from pymodbus.exceptions import ModbusIOException

from ..client.modbus_client import ModbusClient
from ..client.modbus_client import ModbusClientFailedError
Expand All @@ -23,6 +21,8 @@
from ..inverter_adapters import InverterAdapter
from ..inverter_adapters import InverterAdapterType
from ..modbus_controller import ModbusController
from ..vendor.pymodbus import ConnectionException
from ..vendor.pymodbus import ModbusIOException
from .flow_handler_mixin import FlowHandlerMixin
from .flow_handler_mixin import ValidationFailedError
from .inverter_data import InverterData
Expand Down
1 change: 0 additions & 1 deletion custom_components/foxess_modbus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"integration_type": "service",
"iot_class": "local_push",
"issue_tracker": "https://github.com/nathanmarlor/foxess_modbus/issues",
"requirements": ["pymodbus>=3.7.4"],
"version": "1.0.0"
}
2 changes: 1 addition & 1 deletion custom_components/foxess_modbus/modbus_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from homeassistant.helpers import issue_registry
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.issue_registry import IssueSeverity
from pymodbus.exceptions import ConnectionException

from .client.modbus_client import ModbusClient
from .client.modbus_client import ModbusClientFailedError
Expand All @@ -38,6 +37,7 @@
from .inverter_profiles import INVERTER_PROFILES
from .inverter_profiles import InverterModelConnectionTypeProfile
from .remote_control_manager import RemoteControlManager
from .vendor.pymodbus import ConnectionException

_LOGGER = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from homeassistant.core import ServiceCall
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
from pymodbus.exceptions import ModbusIOException

from ..const import DOMAIN
from ..entities.modbus_charge_period_sensors import is_time_value_valid
from ..entities.modbus_charge_period_sensors import parse_time_value
from ..entities.modbus_charge_period_sensors import serialize_time_to_value
from ..modbus_controller import ModbusController
from ..vendor.pymodbus import ModbusIOException
from .utils import get_controller_from_friendly_name_or_device_id

_LOGGER: logging.Logger = logging.getLogger(__package__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from homeassistant.core import ServiceCall
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
from pymodbus.exceptions import ModbusIOException

from ..const import DOMAIN
from ..modbus_controller import ModbusController
from ..vendor.pymodbus import ModbusIOException
from .utils import get_controller_from_friendly_name_or_device_id

_LOGGER: logging.Logger = logging.getLogger(__package__)
Expand Down
34 changes: 34 additions & 0 deletions custom_components/foxess_modbus/vendor/pymodbus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from pathlib import Path

# Update python.analysis.extraPaths in .vscode/settings.json if you change this.
# If changed, make sure subclasses in modbus_client are still valid!
sys.path.insert(0, str((Path(__file__).parent / "pymodbus-3.7.4").absolute()))

from pymodbus.client import ModbusSerialClient
from pymodbus.client import ModbusTcpClient
from pymodbus.client import ModbusUdpClient
from pymodbus.exceptions import ConnectionException
from pymodbus.exceptions import ModbusIOException
from pymodbus.framer import FramerType
from pymodbus.pdu import ModbusPDU
from pymodbus.pdu.register_read_message import ReadHoldingRegistersResponse
from pymodbus.pdu.register_read_message import ReadInputRegistersResponse
from pymodbus.pdu.register_write_message import WriteMultipleRegistersResponse
from pymodbus.pdu.register_write_message import WriteSingleRegisterResponse

sys.path.pop(0)

__all__ = [
"ModbusSerialClient",
"ModbusTcpClient",
"ModbusUdpClient",
"ConnectionException",
"ModbusIOException",
"FramerType",
"ModbusPDU",
"ReadHoldingRegistersResponse",
"ReadInputRegistersResponse",
"WriteMultipleRegistersResponse",
"WriteSingleRegisterResponse",
]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
Authors
=======
All these versions would not be possible without volunteers!

This is a complete list for each major version.

A big "thank you" to everybody who helped out.

Pymodbus version 3 family
-------------------------
Thanks to

- ahcm-dev
- AKJ7
- Alex
- Alex Ruddick
- Alexander Lanin
- Alexandre CUER
- Alois Hockenschlohe
- Andy Walker
- Arjan
- André Srinivasan
- andrew-harness
- banana-sun
- Blaise Thompson
- CapraTheBest
- cgernert
- corollaries
- Chandler Riehm
- Chris Hung
- Christian Krause
- Daniel Rauber
- dhoomakethu
- doelki
- DominicDataP
- Dominique Martinet
- Dries
- duc996
- efdx
- Esco441-91
- Farzad Panahi
- Fredo70
- Gao Fang
- Ghostkeeper
- Hangyu Fan
- Hayden Roche
- Iktek
- Ilkka Ollakka
- Jakob Ruhe
- Jakob Schlyter
- James Braza
- James Cameron
- James Hilliard
- jan iversen
- Jerome Velociter
- Joe Burmeister
- John Miko
- Jonathan Reichelt Gjertsen
- julian
- Justin Standring
- Kenny Johansson
- Kürşat Aktaş
- laund
- Logan Gunthorpe
- Marko Luther
- Martyy
- Máté Szabó
- Matthias Straka
- Matthias Urlichs
- Michel F
- Mickaël Schoentgen
- Pavel Kostromitinov
- peufeu2
- Philip Couling
- Qi Li
- Sebastian Machuca
- Sefa Keleş
- Steffen Beyer
- sumguytho
- Thijs W
- Totally a booplicate
- WouterTuinstra
- wriswith
- Yash Jani
- Yohrog
- yyokusa


Pymodbus version 2 family
-------------------------
Thanks to

- alecjohanson
- Alexey Andreyev
- Andrea Canidio
- Carlos Gomez
- Cougar
- Christian Sandberg
- dhoomakethu
- dices
- Dmitri Zimine
- Emil Vanherp
- er888kh
- Eric Duminil
- Erlend Egeberg Aasland
- hackerboygn
- Jian-Hong Pan
- Jose J Rodriguez
- Justin Searle
- Karl Palsson
- Kim Hansen
- Kristoffer Sjöberg
- Kyle Altendorf
- Lars Kruse
- Malte Kliemann
- Memet Bilgin
- Michael Corcoran
- Mike
- sanjay
- Sekenre
- Siarhei Farbotka
- Steffen Vogel
- tcplomp
- Thor Michael Støre
- Tim Gates
- Ville Skyttä
- Wild Stray
- Yegor Yefremov


Pymodbus version 1 family
-------------------------
Thanks to

- Antoine Pitrou
- Bart de Waal
- bashwork
- bje-
- Claudio Catterina
- Chintalagiri Shashank
- dhoomakethu
- dragoshenron
- Elvis Stansvik
- Eren Inan Canpolat
- Everley
- Fabio Bonelli
- fleimgruber
- francozappa
- Galen Collins
- Gordon Broom
- Hamilton Kibbe
- Hynek Petrak
- idahogray
- Ingo van Lil
- Jack
- jbiswas
- jon mills
- Josh Kelley
- Karl Palsson
- Matheus Frata
- Patrick Fuller
- Perry Kundert
- Philippe Gauthier
- Rahul Raghunath
- sanjay
- schubduese42
- semyont
- Semyon Teplitsky
- Stuart Longland
- Yegor Yefremov


Pymodbus version 0 family
-------------------------
Thanks to

- Albert Brandl
- Galen Collins

Import to github was based on code from:

- S.W.A.C. GmbH, Germany.
- S.W.A.C. Bohemia s.r.o., Czech Republic.
- Hynek Petrak
- Galen Collins
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright 2008-2023 Pymodbus

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 8b7f87d

Please sign in to comment.