Skip to content

Commit e3c3ccd

Browse files
authored
Merge pull request #2122 from rosenrot00/times
Replace time selects with native time entities
2 parents 50b89c3 + 1875c03 commit e3c3ccd

4 files changed

Lines changed: 405 additions & 447 deletions

File tree

custom_components/solax_modbus/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,22 +1584,23 @@ def treat_address(self, data: dict[str, Any], regs: list[int], idx: int, descr:
15841584
return_value = round(val * descr.scale * read_scale, descr.rounding)
15851585
except Exception:
15861586
return_value = val # probably a REGISTER_WORDS instance
1587-
if descr.native_unit_of_measurement == UnitOfFrequency.HERTZ:
1587+
native_unit = getattr(descr, "native_unit_of_measurement", None)
1588+
if native_unit == UnitOfFrequency.HERTZ:
15881589
min_val = getattr(descr, "min_value", 20)
15891590
max_val = getattr(descr, "max_value", 80)
1590-
if descr.native_unit_of_measurement == PERCENTAGE:
1591+
if native_unit == PERCENTAGE:
15911592
min_val = getattr(descr, "min_value", 0)
15921593
max_val = getattr(descr, "max_value", 100)
1593-
elif descr.native_unit_of_measurement == UnitOfTemperature.CELSIUS:
1594+
elif native_unit == UnitOfTemperature.CELSIUS:
15941595
min_val = getattr(descr, "min_value", -100)
15951596
max_val = getattr(descr, "max_value", 200)
1596-
elif descr.native_unit_of_measurement == UnitOfPower.KILO_WATT:
1597+
elif native_unit == UnitOfPower.KILO_WATT:
15971598
min_val = getattr(descr, "min_value", -self.inverterPowerKw * 2)
15981599
max_val = getattr(descr, "max_value", +self.inverterPowerKw * 2)
1599-
elif descr.native_unit_of_measurement == UnitOfElectricCurrent.AMPERE:
1600+
elif native_unit == UnitOfElectricCurrent.AMPERE:
16001601
min_val = getattr(descr, "min_value", -self.inverterPowerKw * 2)
16011602
max_val = getattr(descr, "max_value", +self.inverterPowerKw * 2)
1602-
elif descr.native_unit_of_measurement == UnitOfElectricPotential.VOLT:
1603+
elif native_unit == UnitOfElectricPotential.VOLT:
16031604
min_val = getattr(descr, "min_value", 0)
16041605
max_val = getattr(descr, "max_value", 2000)
16051606
else:

custom_components/solax_modbus/const.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,26 @@ class BaseModbusTimeEntityDescription(TimeEntityDescription):
309309
allowedtypes: int = 0 # overload with ALLDEFAULT from plugin
310310
modbus_min: int | None = None # Minimum supported Modbus protocol document version, e.g. 102 for V001.02.
311311
modbus_max: int | None = None # Maximum supported Modbus protocol document version.
312-
register: int | None = None
312+
scale: float | dict[Any, Any] | Callable[[Any, Any, dict[str, Any]], Any] = 1
313+
read_scale_exceptions: list[Any] | None = None
314+
read_scale: float = 1
315+
register: int = -1
316+
rounding: int = 1
317+
register_type: int | None = None # REG_HOLDING or REG_INPUT or REG_DATA
318+
register_data_type: str | None = REGISTER_U16 # REGISTER_U16, REGISTER_S32, REGISTER_F32, etc.
319+
scan_group: str | None = None # SCAN_GROUP_MEDIUM, SCAN_GROUP_FAST, SCAN_GROUP_DEFAULT, etc.
320+
newblock: bool = False # set to True to start a new modbus read block operation
313321
option_dict: dict[int, str] | None = None
314322
reverse_option_dict: dict[str, int] | None = None # autocomputed
315323
blacklist: list[str] | None = None # none or list of serial number prefixes
316324
write_method: int = WRITE_SINGLE_MODBUS # WRITE_SINGLE_MOBUS or WRITE_MULTI_MODBUS or WRITE_DATA_LOCAL
317325
initvalue: int | None = None # initial default value for WRITE_DATA_LOCAL entities
318-
register_data_type: str | None = None # REGISTER_U16, REGISTER_S32, REGISTER_F32, etc.
319326
wordcount: int | None = None # number of registers to write (for separate register format, e.g., hours and minutes in adjacent registers)
327+
sleepmode: int | None = SLEEPMODE_LAST # or SLEEPMODE_ZERO, SLEEPMODE_NONE or SLEEPMODE_LASTAWAKE
328+
ignore_readerror: bool | Any = False
329+
min_value: int | None = None
330+
max_value: int | None = None
331+
depends_on: list[str] | None = None # list of modbus register keys that must be read
320332

321333

322334
@dataclass(kw_only=True, frozen=True)

0 commit comments

Comments
 (0)