Skip to content

Commit

Permalink
Add Eco Charge and Eco Discharge operation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed Jan 10, 2022
1 parent 16795c2 commit 44e647a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/goodwe/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
# read current time from the inverter
try:
await inverter.read_setting("time")
except Exception:
except (InverterError, ValueError):
# Inverter model does not support clock synchronization
_LOGGER.debug("Could not read inverter current clock time")
else:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/goodwe/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@starkillerOG",
"@fizcris"
],
"requirements": ["goodwe==0.2.13"],
"requirements": ["goodwe==0.2.14"],
"config_flow": true,
"iot_class": "local_polling",
"version": "1.0.0"
Expand Down
15 changes: 14 additions & 1 deletion custom_components/goodwe/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class GoodweNumberEntityDescription(
getter=lambda inv: inv.get_ongrid_battery_dod(),
setter=lambda inv, val: inv.set_ongrid_battery_dod(val),
),
GoodweNumberEntityDescription(
key="eco_mode_power",
name="Eco mode power",
icon="mdi:battery-charging-low",
entity_category=ENTITY_CATEGORY_CONFIG,
unit_of_measurement=PERCENTAGE,
getter=lambda inv: inv.get_operation_mode(),
setter=None,
),
)


Expand All @@ -63,7 +72,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
for description in NUMBERS:
try:
current_value = await description.getter(inverter)
except Exception:
except (InverterError, ValueError):
# Inverter model does not support this setting
_LOGGER.debug("Could not read inverter setting %s", description.key)
continue
Expand All @@ -77,6 +86,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entity._attr_max_value = 99
entity._attr_min_value = 0
entity._attr_step = 1
if description.key == "eco_mode_power":
entity._attr_max_value = 100
entity._attr_min_value = 0
entity._attr_step = 1

entities.append(entity)

Expand Down
10 changes: 8 additions & 2 deletions custom_components/goodwe/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"Off grid mode",
"Backup mode",
"Eco mode",
"Eco charge mode",
"Eco discharge mode",
]

OPERATION_MODE = SelectEntityDescription(
Expand All @@ -35,7 +37,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
# read current operating mode from the inverter
try:
active_mode = await inverter.get_operation_mode()
except Exception:
except (InverterError, ValueError):
# Inverter model does not support this setting
_LOGGER.debug("Could not read inverter operation mode")
else:
Expand Down Expand Up @@ -74,6 +76,10 @@ def __init__(

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
await self._inverter.set_operation_mode(INVERTER_OPERATION_MODES.index(option))
operation_mode = INVERTER_OPERATION_MODES.index(option)
eco_mode_power = 100
if operation_mode in (4, 5):
eco_mode_power = self.hass.states.get("number.eco_mode_power").state
await self._inverter.set_operation_mode(operation_mode, eco_mode_power)
self._attr_current_option = option
self.async_write_ha_state()

0 comments on commit 44e647a

Please sign in to comment.