Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added min_discharge to set_powerlimits + preserving set values #176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions custom_components/e3dc_rscp/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,39 +583,59 @@ async def async_set_wallbox_max_charge_current(self, current: int | None, wallbo
_LOGGER.debug("Successfully set the wallbox max charge current to %s", current)

async def async_set_power_limits(
self, max_charge: int | None, max_discharge: int | None
self, max_charge: int | None, max_discharge: int | None, min_discharge: int | None
) -> None:
"""Set the given power limits and enable them."""

# Validate the arguments, at least one has to be set.
if max_charge is None and max_discharge is None:
if max_charge is None and max_discharge is None and min_discharge is None:
raise ValueError(
"async_set_power_limits must be called with at least one of "
"max_charge or max_discharge."
"max_charge, max_discharge or min_discharge."
)

if max_charge is not None and max_charge > self.proxy.e3dc.maxBatChargePower:
_LOGGER.warning(
"Limiting max_charge to %s", self.proxy.e3dc.maxBatChargePower
)
max_charge = self.proxy.e3dc.maxBatChargePower
if (
max_discharge is not None
and max_discharge > self.proxy.e3dc.maxBatDischargePower
):
elif max_charge is None:
_LOGGER.debug(
"Preserving max_charge at %s", self._mydata["pset-limit-charge"]
)
max_charge = self._mydata["pset-limit-charge"]

if max_discharge is not None and max_discharge > self.proxy.e3dc.maxBatDischargePower:
_LOGGER.warning(
"Limiting max_discharge to %s", self.proxy.e3dc.maxBatDischargePower
)
max_discharge = self.proxy.e3dc.maxBatDischargePower
elif max_discharge is None:
_LOGGER.debug(
"Preserving max_discharge at %s", self._mydata["pset-limit-discharge"]
)
max_discharge = self._mydata["pset-limit-discharge"]

if min_discharge is not None and min_discharge > self.proxy.e3dc.maxBatDischargePower:
_LOGGER.warning(
"Limiting min_discharge to %s", self.proxy.e3dc.maxBatDischargePower
)
min_discharge = self.proxy.e3dc.maxBatDischargePower
elif min_discharge is None:
_LOGGER.debug(
"Preserving min_discharge at %s", self._mydata["pset-limit-discharge-minimum"]
)
min_discharge = self._mydata["pset-limit-discharge-minimum"]

_LOGGER.debug(
"Enabling power limits, max_charge: %s, max_discharge: %s",
"Enabling power limits, max_charge: %s, max_discharge: %s, min_discharge: %s",
max_charge,
max_discharge,
min_discharge
)

await self.hass.async_add_executor_job(
self.proxy.set_power_limits, True, max_charge, max_discharge, None
self.proxy.set_power_limits, True, max_charge, max_discharge, min_discharge
)

_LOGGER.debug("Successfully set the power limits")
Expand Down
9 changes: 6 additions & 3 deletions custom_components/e3dc_rscp/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ATTR_DEVICEID = "device_id"
ATTR_MAX_CHARGE = "max_charge"
ATTR_MAX_DISCHARGE = "max_discharge"
ATTR_MIN_DISCHARGE = "min_discharge"
ATTR_CHARGE_AMOUNT = "charge_amount"
ATTR_MAX_CHARGE_CURRENT = "max_charge_current"

Expand All @@ -40,6 +41,7 @@
vol.Required(ATTR_DEVICEID): str,
vol.Optional(ATTR_MAX_CHARGE): vol.All(int, vol.Range(min=0)),
vol.Optional(ATTR_MAX_DISCHARGE): vol.All(int, vol.Range(min=0)),
vol.Optional(ATTR_MIN_DISCHARGE): vol.All(int, vol.Range(min=0))
}
)

Expand Down Expand Up @@ -196,12 +198,13 @@ async def _async_set_power_limits(hass: HomeAssistant, call: ServiceCall) -> Non
)
max_charge: int | None = call.data.get(ATTR_MAX_CHARGE)
max_discharge: int | None = call.data.get(ATTR_MAX_DISCHARGE)
if max_charge is None and max_discharge is None:
min_discharge: int | None = call.data.get(ATTR_MIN_DISCHARGE)
if max_charge is None and max_discharge is None and min_discharge is None:
raise HomeAssistantError(
f"{SERVICE_SET_POWER_LIMITS}: Need to set at least one of {ATTR_MAX_CHARGE} or {ATTR_MAX_DISCHARGE}"
f"{SERVICE_SET_POWER_LIMITS}: Need to set at least one of {ATTR_MAX_CHARGE}, {ATTR_MAX_DISCHARGE} or {ATTR_MIN_DISCHARGE}"
)
await coordinator.async_set_power_limits(
max_charge=max_charge, max_discharge=max_discharge
max_charge=max_charge, max_discharge=max_discharge, min_discharge=min_discharge
)


Expand Down
10 changes: 9 additions & 1 deletion custom_components/e3dc_rscp/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ set_power_limits:
unit_of_measurement: W
mode: box
step: 100

min_discharge:
required: false
example: "100"
selector:
number:
min: 0
unit_of_measurement: W
mode: box
step: 10
set_wallbox_max_charge_current:
fields:
device_id:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/e3dc_rscp/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
"max_discharge": {
"name": "Maximum Discharge (W)",
"description": "Maximum allowed battery discharge in Watts."
},
"min_discharge": {
"name": "Minimum Discharge (W)",
"description": "Minimum allowed battery discharge in Watts."
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions custom_components/e3dc_rscp/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
"max_discharge": {
"name": "Maximum Discharge (W)",
"description": "Maximum allowed battery discharge in Watts."
},
"min_discharge": {
"name": "Minimum Discharge (W)",
"description": "Minimum allowed battery discharge in Watts."
}
}
},
Expand Down
Loading