Fix grid_export_limit unit for DT inverters (#77290)
FIx grid_export_limit unit for DT inverterspull/77324/head
parent
abaf89f57d
commit
c169a957ab
|
@ -25,6 +25,7 @@ class GoodweNumberEntityDescriptionBase:
|
||||||
|
|
||||||
getter: Callable[[Inverter], Awaitable[int]]
|
getter: Callable[[Inverter], Awaitable[int]]
|
||||||
setter: Callable[[Inverter, int], Awaitable[None]]
|
setter: Callable[[Inverter, int], Awaitable[None]]
|
||||||
|
filter: Callable[[Inverter], bool]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -35,17 +36,33 @@ class GoodweNumberEntityDescription(
|
||||||
|
|
||||||
|
|
||||||
NUMBERS = (
|
NUMBERS = (
|
||||||
|
# non DT inverters (limit in W)
|
||||||
GoodweNumberEntityDescription(
|
GoodweNumberEntityDescription(
|
||||||
key="grid_export_limit",
|
key="grid_export_limit",
|
||||||
name="Grid export limit",
|
name="Grid export limit",
|
||||||
icon="mdi:transmission-tower",
|
icon="mdi:transmission-tower",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
native_unit_of_measurement=POWER_WATT,
|
native_unit_of_measurement=POWER_WATT,
|
||||||
getter=lambda inv: inv.get_grid_export_limit(),
|
|
||||||
setter=lambda inv, val: inv.set_grid_export_limit(val),
|
|
||||||
native_step=100,
|
native_step=100,
|
||||||
native_min_value=0,
|
native_min_value=0,
|
||||||
native_max_value=10000,
|
native_max_value=10000,
|
||||||
|
getter=lambda inv: inv.get_grid_export_limit(),
|
||||||
|
setter=lambda inv, val: inv.set_grid_export_limit(val),
|
||||||
|
filter=lambda inv: type(inv).__name__ != "DT",
|
||||||
|
),
|
||||||
|
# DT inverters (limit is in %)
|
||||||
|
GoodweNumberEntityDescription(
|
||||||
|
key="grid_export_limit",
|
||||||
|
name="Grid export limit",
|
||||||
|
icon="mdi:transmission-tower",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
native_step=1,
|
||||||
|
native_min_value=0,
|
||||||
|
native_max_value=100,
|
||||||
|
getter=lambda inv: inv.get_grid_export_limit(),
|
||||||
|
setter=lambda inv, val: inv.set_grid_export_limit(val),
|
||||||
|
filter=lambda inv: type(inv).__name__ == "DT",
|
||||||
),
|
),
|
||||||
GoodweNumberEntityDescription(
|
GoodweNumberEntityDescription(
|
||||||
key="battery_discharge_depth",
|
key="battery_discharge_depth",
|
||||||
|
@ -53,11 +70,12 @@ NUMBERS = (
|
||||||
icon="mdi:battery-arrow-down",
|
icon="mdi:battery-arrow-down",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
getter=lambda inv: inv.get_ongrid_battery_dod(),
|
|
||||||
setter=lambda inv, val: inv.set_ongrid_battery_dod(val),
|
|
||||||
native_step=1,
|
native_step=1,
|
||||||
native_min_value=0,
|
native_min_value=0,
|
||||||
native_max_value=99,
|
native_max_value=99,
|
||||||
|
getter=lambda inv: inv.get_ongrid_battery_dod(),
|
||||||
|
setter=lambda inv, val: inv.set_ongrid_battery_dod(val),
|
||||||
|
filter=lambda inv: True,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,7 +91,7 @@ async def async_setup_entry(
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for description in NUMBERS:
|
for description in filter(lambda dsc: dsc.filter(inverter), NUMBERS):
|
||||||
try:
|
try:
|
||||||
current_value = await description.getter(inverter)
|
current_value = await description.getter(inverter)
|
||||||
except (InverterError, ValueError):
|
except (InverterError, ValueError):
|
||||||
|
@ -82,7 +100,7 @@ async def async_setup_entry(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entities.append(
|
entities.append(
|
||||||
InverterNumberEntity(device_info, description, inverter, current_value),
|
InverterNumberEntity(device_info, description, inverter, current_value)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
Loading…
Reference in New Issue