Compare commits

...

3 Commits

Author SHA1 Message Date
suaveolent
255a9109d8 update readme 2024-09-09 10:47:00 +02:00
suaveolent
c600d5af4c version bump 2024-09-09 10:46:14 +02:00
suaveolent
26148448cb add local_addr parameter to allow to bind to specific interface 2024-09-09 10:45:26 +02:00
4 changed files with 16 additions and 7 deletions

View File

@ -2,7 +2,7 @@
This Python library facilitates communication with Hoymiles DTUs and the HMS-XXXXW-2T HMS microinverters, utilizing protobuf messages. This Python library facilitates communication with Hoymiles DTUs and the HMS-XXXXW-2T HMS microinverters, utilizing protobuf messages.
For the Home Assistant integration have a look here: For the Home Assistant integration have a look here:
https://github.com/suaveolent/ha-hoymiles-wifi https://github.com/suaveolent/ha-hoymiles-wifi
**Disclaimer: This library is not affiliated with Hoymiles. It is an independent project developed to provide tools for interacting with Hoymiles HMS-XXXXW-2T series micro-inverters featuring integrated WiFi DTU. Any trademarks or product names mentioned are the property of their respective owners.** **Disclaimer: This library is not affiliated with Hoymiles. It is an independent project developed to provide tools for interacting with Hoymiles HMS-XXXXW-2T series micro-inverters featuring integrated WiFi DTU. Any trademarks or product names mentioned are the property of their respective owners.**
@ -27,7 +27,7 @@ You can integrate the library into your own project, or simply use it in the com
### Command line: ### Command line:
``` ```
hoymiles-wifi [-h] --host HOST [--as-json] <command> hoymiles-wifi [-h] --host HOST [--local_addr IP_OF_INTERFACE_TO_USE] [--as-json] <command>
commands: commands:
get-real-data-new, get-real-data-new,

View File

@ -314,6 +314,12 @@ async def main() -> None:
parser.add_argument( parser.add_argument(
"--host", type=str, required=True, help="IP address or hostname of the DTU" "--host", type=str, required=True, help="IP address or hostname of the DTU"
) )
parser.add_argument(
"--local_addr",
type=str,
required=False,
help="IP address of the interface to bind to",
)
parser.add_argument( parser.add_argument(
"--as-json", "--as-json",
action="store_true", action="store_true",
@ -347,7 +353,7 @@ async def main() -> None:
) )
args = parser.parse_args() args = parser.parse_args()
dtu = DTU(args.host) dtu = DTU(args.host, args.local_addr)
# Execute the specified command using a switch case # Execute the specified command using a switch case
switch = { switch = {

View File

@ -70,10 +70,11 @@ class NetworkState(Enum):
class DTU: class DTU:
"""DTU class.""" """DTU class."""
def __init__(self, host: str): def __init__(self, host: str, local_addr: str = None):
"""Initialize DTU class.""" """Initialize DTU class."""
self.host = host self.host = host
self.local_addr = local_addr
self.state = NetworkState.Unknown self.state = NetworkState.Unknown
self.sequence = 0 self.sequence = 0
self.mutex = asyncio.Lock() self.mutex = asyncio.Lock()
@ -365,11 +366,13 @@ class DTU:
+ request_as_bytes + request_as_bytes
) )
address = (self.host, dtu_port) ip_to_bind = (self.local_addr, 0) if self.local_addr is not None else None
async with self.mutex: async with self.mutex:
try: try:
reader, writer = await asyncio.open_connection(*address) reader, writer = await asyncio.open_connection(
host=self.host, port=dtu_port, local_addr=ip_to_bind
)
writer.write(message) writer.write(message)
await writer.drain() await writer.drain()

View File

@ -6,7 +6,7 @@ setup(
name="hoymiles-wifi", name="hoymiles-wifi",
packages=["hoymiles_wifi", "hoymiles_wifi.protobuf"], packages=["hoymiles_wifi", "hoymiles_wifi.protobuf"],
install_requires=["protobuf", "crcmod"], install_requires=["protobuf", "crcmod"],
version="0.2.3", version="0.2.4",
description="A python library for interfacing with the Hoymiles DTUs and the HMS-XXXXW-2T series of micro-inverters using protobuf messages.", description="A python library for interfacing with the Hoymiles DTUs and the HMS-XXXXW-2T series of micro-inverters using protobuf messages.",
author="suaveolent", author="suaveolent",
include_package_data=True, include_package_data=True,