Skip to content

Commit

Permalink
Add services for other Active Power Control modes
Browse files Browse the repository at this point in the history
Fixes: #387
  • Loading branch information
wlcrs committed Jul 17, 2023
1 parent 71006e1 commit 7ec4d7d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
4 changes: 4 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
SERVICE_STOP_FORCIBLE_CHARGE = "stop_forcible_charge"

SERVICE_RESET_MAXIMUM_FEED_GRID_POWER = "reset_maximum_feed_grid_power"
SERVICE_SET_DI_ACTIVE_POWER_SCHEDULING = "set_di_active_power_scheduling"
SERVICE_SET_ZERO_POWER_GRID_CONNECTION = "set_zero_power_grid_connection"
SERVICE_SET_MAXIMUM_FEED_GRID_POWER = "set_maximum_feed_grid_power"
SERVICE_SET_MAXIMUM_FEED_GRID_POWER_PERCENT = "set_maximum_feed_grid_power_percent"
SERVICE_SET_TOU_PERIODS = "set_tou_periods"
Expand All @@ -42,6 +44,8 @@
SERVICE_FORCIBLE_DISCHARGE_SOC,
SERVICE_STOP_FORCIBLE_CHARGE,
SERVICE_RESET_MAXIMUM_FEED_GRID_POWER,
SERVICE_SET_DI_ACTIVE_POWER_SCHEDULING,
SERVICE_SET_ZERO_POWER_GRID_CONNECTION,
SERVICE_SET_MAXIMUM_FEED_GRID_POWER,
SERVICE_SET_TOU_PERIODS,
SERVICE_SET_CAPACITY_CONTROL_PERIODS,
Expand Down
47 changes: 46 additions & 1 deletion services.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
SERVICE_FORCIBLE_DISCHARGE,
SERVICE_FORCIBLE_DISCHARGE_SOC,
SERVICE_RESET_MAXIMUM_FEED_GRID_POWER,
SERVICE_SET_DI_ACTIVE_POWER_SCHEDULING,
SERVICE_SET_ZERO_POWER_GRID_CONNECTION,
SERVICE_SET_CAPACITY_CONTROL_PERIODS,
SERVICE_SET_FIXED_CHARGE_PERIODS,
SERVICE_SET_MAXIMUM_FEED_GRID_POWER,
Expand Down Expand Up @@ -306,7 +308,7 @@ async def stop_forcible_charge(service_call: ServiceCall) -> None:
await bridge.set(rn.STORAGE_FORCIBLE_CHARGE_DISCHARGE_SETTING_MODE, 0)

async def reset_maximum_feed_grid_power(service_call: ServiceCall) -> None:
"""Sets Active Power Control to 'Power-limited grid connection' with the given wattage."""
"""Sets Active Power Control to 'Unlimited'"""

bridge = get_inverter_bridge(service_call)
await bridge.set(
Expand All @@ -319,6 +321,35 @@ async def reset_maximum_feed_grid_power(service_call: ServiceCall) -> None:
0,
)

async def set_di_active_power_scheduling(service_call: ServiceCall) -> None:
"""Sets Active Power Control to 'DI active scheduling'"""

bridge = get_inverter_bridge(service_call)
await bridge.set(
rn.ACTIVE_POWER_CONTROL_MODE,
rv.ActivePowerControlMode.DI_ACTIVE_SCHEDULING,
)
await bridge.set(rn.MAXIMUM_FEED_GRID_POWER_WATT, 0)
await bridge.set(
rn.MAXIMUM_FEED_GRID_POWER_PERCENT,
0,
)

async def set_zero_power_grid_connection(service_call: ServiceCall) -> None:
"""Sets Active Power Control to 'Zero-Power Grid Connection'"""

bridge = get_inverter_bridge(service_call)
await bridge.set(
rn.ACTIVE_POWER_CONTROL_MODE,
rv.ActivePowerControlMode.ZERO_POWER_GRID_CONNECTION,
)
await bridge.set(rn.MAXIMUM_FEED_GRID_POWER_WATT, 0)
await bridge.set(
rn.MAXIMUM_FEED_GRID_POWER_PERCENT,
0,
)


async def set_maximum_feed_grid_power(service_call: ServiceCall) -> None:
"""Sets Active Power Control to 'Power-limited grid connection' with the given wattage."""

Expand Down Expand Up @@ -471,6 +502,20 @@ def _parse_periods(text) -> list[ChargeDischargePeriod]:
schema=DEVICE_SCHEMA,
)

hass.services.async_register(
DOMAIN,
SERVICE_SET_DI_ACTIVE_POWER_SCHEDULING,
set_di_active_power_scheduling,
schema=DEVICE_SCHEMA,
)

hass.services.async_register(
DOMAIN,
SERVICE_SET_ZERO_POWER_GRID_CONNECTION,
set_zero_power_grid_connection,
schema=DEVICE_SCHEMA,
)

hass.services.async_register(
DOMAIN,
SERVICE_SET_MAXIMUM_FEED_GRID_POWER,
Expand Down
26 changes: 25 additions & 1 deletion services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ reset_maximum_feed_grid_power:
device:
integration: huawei_solar

set_di_active_power_scheduling:
name: Set Active Power Control to Unlimited mode
description: Set Active Power Control to 'DI active scheduling'
fields:
device_id:
name: Inverter
description: Must be an 'Inverter' device
required: true
selector:
device:
integration: huawei_solar

set_zero_power_grid_connection:
name: Set Active Power Control to Unlimited mode
description: Set Active Power Control to 'Zero power grid connection'
fields:
device_id:
name: Inverter
description: Must be an 'Inverter' device
required: true
selector:
device:
integration: huawei_solar

set_maximum_feed_grid_power:
name: Limit the power fed to the grid
description: Sets Active Power Control to 'Power-limited grid connection' with the given wattage
Expand Down Expand Up @@ -236,4 +260,4 @@ set_fixed_charge_periods:
required: true
selector:
text:
multiline: true
multiline: true

0 comments on commit 7ec4d7d

Please sign in to comment.