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]]
|
||||
setter: Callable[[Inverter, int], Awaitable[None]]
|
||||
filter: Callable[[Inverter], bool]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -35,17 +36,33 @@ class GoodweNumberEntityDescription(
|
|||
|
||||
|
||||
NUMBERS = (
|
||||
# non DT inverters (limit in W)
|
||||
GoodweNumberEntityDescription(
|
||||
key="grid_export_limit",
|
||||
name="Grid export limit",
|
||||
icon="mdi:transmission-tower",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
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_min_value=0,
|
||||
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(
|
||||
key="battery_discharge_depth",
|
||||
|
@ -53,11 +70,12 @@ NUMBERS = (
|
|||
icon="mdi:battery-arrow-down",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
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_min_value=0,
|
||||
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 = []
|
||||
|
||||
for description in NUMBERS:
|
||||
for description in filter(lambda dsc: dsc.filter(inverter), NUMBERS):
|
||||
try:
|
||||
current_value = await description.getter(inverter)
|
||||
except (InverterError, ValueError):
|
||||
|
@ -82,7 +100,7 @@ async def async_setup_entry(
|
|||
continue
|
||||
|
||||
entities.append(
|
||||
InverterNumberEntity(device_info, description, inverter, current_value),
|
||||
InverterNumberEntity(device_info, description, inverter, current_value)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
Loading…
Reference in New Issue