Skip to content

Commit c87a3fa

Browse files
authored
Merge pull request #2201 from rosenrot00/feat/growatt-pv-start-voltage
Add Growatt PV start-up voltage sensor and control
2 parents 468c5d4 + a4b9e8b commit c87a3fa

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

custom_components/solax_modbus/plugin_growatt.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,23 @@ def value_function_inverter_module(initval: int, descr: Any, datadict: dict[str,
877877
native_unit_of_measurement=PERCENTAGE,
878878
allowedtypes=ALL_GEN_GROUP,
879879
),
880+
GrowattModbusNumberEntityDescription(
881+
name="PV Start-up Voltage",
882+
key="pv_startup_voltage",
883+
register=17,
884+
register_data_type=REGISTER_U16,
885+
fmt="i",
886+
scale=0.1,
887+
native_min_value=0,
888+
native_max_value=1000,
889+
native_step=0.1,
890+
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
891+
device_class=NumberDeviceClass.VOLTAGE,
892+
allowedtypes=HYBRID | GEN3,
893+
write_method=WRITE_SINGLE_MODBUS,
894+
entity_category=EntityCategory.CONFIG,
895+
icon="mdi:solar-power",
896+
),
880897
GrowattModbusNumberEntityDescription(
881898
name="Grid Export Limit",
882899
key="grid_export_limit",
@@ -1954,6 +1971,17 @@ def value_function_inverter_module(initval: int, descr: Any, datadict: dict[str,
19541971
allowedtypes=ALL_GEN_GROUP,
19551972
internal=True,
19561973
),
1974+
GrowattModbusSensorEntityDescription(
1975+
name="PV Start-up Voltage",
1976+
key="pv_startup_voltage",
1977+
register=17,
1978+
register_data_type=REGISTER_U16,
1979+
scale=0.1,
1980+
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
1981+
device_class=SensorDeviceClass.VOLTAGE,
1982+
allowedtypes=HYBRID | GEN3,
1983+
icon="mdi:solar-power",
1984+
),
19571985
GrowattModbusSensorEntityDescription(
19581986
name="Firmware Version",
19591987
key="firmware_version",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from homeassistant.components.number import NumberDeviceClass
2+
from homeassistant.components.sensor import SensorDeviceClass
3+
from homeassistant.const import UnitOfElectricPotential
4+
from homeassistant.helpers.entity import EntityCategory # type: ignore[attr-defined]
5+
6+
from custom_components.solax_modbus.const import REGISTER_U16, WRITE_SINGLE_MODBUS
7+
from custom_components.solax_modbus.number import _scale_native_value_to_register
8+
from custom_components.solax_modbus.plugin_growatt import (
9+
GEN3,
10+
GEN4,
11+
HYBRID,
12+
NUMBER_TYPES,
13+
PV,
14+
SENSOR_TYPES,
15+
X1,
16+
plugin_instance,
17+
)
18+
19+
20+
def test_growatt_pv_startup_voltage_descriptions() -> None:
21+
number = next(description for description in NUMBER_TYPES if description.key == "pv_startup_voltage")
22+
sensor = next(description for description in SENSOR_TYPES if description.key == "pv_startup_voltage")
23+
24+
assert number.register == sensor.register == 17
25+
assert number.register_data_type == sensor.register_data_type == REGISTER_U16
26+
assert number.scale == sensor.scale == 0.1
27+
assert number.allowedtypes == sensor.allowedtypes == HYBRID | GEN3
28+
assert number.native_unit_of_measurement == sensor.native_unit_of_measurement == UnitOfElectricPotential.VOLT
29+
assert number.device_class == NumberDeviceClass.VOLTAGE
30+
assert sensor.device_class == SensorDeviceClass.VOLTAGE
31+
32+
assert number.native_min_value == 0
33+
assert number.native_max_value == 1000
34+
assert number.native_step == 0.1
35+
assert number.write_method == WRITE_SINGLE_MODBUS
36+
assert number.entity_category == EntityCategory.CONFIG
37+
assert number.entity_registry_enabled_default is True
38+
39+
assert _scale_native_value_to_register(150.0, number.scale, number.read_scale) == 1500
40+
assert plugin_instance.matchInverterWithMask(HYBRID | GEN3 | X1, number.allowedtypes)
41+
assert not plugin_instance.matchInverterWithMask(PV | GEN3 | X1, number.allowedtypes)
42+
assert not plugin_instance.matchInverterWithMask(HYBRID | GEN4 | X1, number.allowedtypes)

0 commit comments

Comments
 (0)