Skip to content

Commit 8f28a63

Browse files
Merge pull request #617 from WillCodeForCats/revert-616-604-allow-non-sequential-device-id-numbers
Revert "Constants for device scan request and response"
2 parents 0105528 + d3ae63f commit 8f28a63

File tree

2 files changed

+0
-103
lines changed

2 files changed

+0
-103
lines changed

custom_components/solaredge_modbus_multi/const.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -372,35 +372,3 @@ class SunSpecNotImpl(IntEnum):
372372
}
373373

374374
LIMIT_CONTROL = {0: "Total", 1: "Per Phase"}
375-
376-
DEV_SCAN_REQUEST = [0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x0, 0x3, 0x9C, 0x40, 0x0, 0x09]
377-
378-
DEV_SCAN_RESPONSE = [
379-
0x0,
380-
0x0,
381-
0x0,
382-
0x0,
383-
0x0,
384-
0x15,
385-
0x0,
386-
0x3,
387-
0x12,
388-
0x53,
389-
0x75,
390-
0x6E,
391-
0x53,
392-
0x0,
393-
0x1,
394-
0x0,
395-
0x41,
396-
0x53,
397-
0x6F,
398-
0x6C,
399-
0x61,
400-
0x72,
401-
0x45,
402-
0x64,
403-
0x67,
404-
0x65,
405-
0x20,
406-
]

custom_components/solaredge_modbus_multi/helpers.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import ipaddress
44
import struct
55

6-
from homeassistant.exceptions import HomeAssistantError
7-
86
from .const import DOMAIN_REGEX
97

108

@@ -45,72 +43,3 @@ def host_valid(host):
4543

4644
except ValueError:
4745
return DOMAIN_REGEX.match(host)
48-
49-
50-
def deviceIdsFromString(value: str) -> list[int]:
51-
"""The function `deviceIdsFromString` takes a string input and returns a list of
52-
device IDs, where the input can be a single ID or a range of IDs separated by commas
53-
54-
Parameters
55-
----------
56-
value
57-
The `value` parameter is a string that represents a list of device IDs. The
58-
device IDs can be specified as individual IDs or as ranges separated by a hyphen
59-
For example, the string "1,3-5,7" represents the device IDs 1, 3, 4, 5 and 7
60-
61-
Returns
62-
-------
63-
The function `checkDeviceIds` returns a list of device IDs.
64-
65-
Credit: https://github.com/thargy/modbus-scanner/blob/main/scan.py
66-
"""
67-
parts = [p.strip() for p in value.split(",")]
68-
ids = []
69-
for p in parts:
70-
r = [i.strip() for i in p.split("-")]
71-
if len(r) < 2:
72-
# We have a single id
73-
ids.append(checkDeviceId(r[0]))
74-
75-
elif len(r) > 2:
76-
# Invalid range, multiple '-'s
77-
raise HomeAssistantError(
78-
f"'{p}' in '{value}' looks like a range but has multiple '-'s."
79-
)
80-
81-
else:
82-
# Looks like a range
83-
start = checkDeviceId(r[0])
84-
end = checkDeviceId(r[1])
85-
if end < start:
86-
raise HomeAssistantError(
87-
f"'{start}' must be less than or equal to {end}."
88-
)
89-
90-
ids.extend(range(start, end + 1))
91-
92-
return sorted(set(ids))
93-
94-
95-
def checkDeviceId(value: str | int) -> int:
96-
"""The `checkDeviceId` function takes a value and checks if it is a valid device
97-
ID between 1 and 247, raising an error if it is not.
98-
99-
Parameters
100-
----------
101-
value
102-
The value parameter is the input value that is
103-
being checked for validity as a device ID.
104-
105-
Returns
106-
-------
107-
the device ID as an integer.
108-
109-
Credit: https://github.com/thargy/modbus-scanner/blob/main/scan.py
110-
"""
111-
id = int(value)
112-
113-
if (id < 1) or id > 247:
114-
raise HomeAssistantError(f"'{value}' must be a device ID between 1 and 247")
115-
116-
return id

0 commit comments

Comments
 (0)