Skip to content

Commit

Permalink
Do not fail with unknown/unsupported operation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 1, 2024
1 parent 4332ba7 commit 0feabc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions goodwe/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,18 @@ async def get_operation_modes(self, include_emulated: bool) -> Tuple[OperationMo
return tuple(result)

async def get_operation_mode(self) -> OperationMode:
mode = OperationMode(await self.read_setting('work_mode'))
mode_id = await self.read_setting('work_mode')
try:
mode = OperationMode(mode_id)
except ValueError:
logger.debug("Unknown work_mode value %d", mode_id)
return None
if OperationMode.ECO != mode:
return mode
ecomode = await self.read_setting('eco_mode_1')
if ecomode.is_eco_charge_mode():
eco_mode = await self.read_setting('eco_mode_1')
if eco_mode.is_eco_charge_mode():
return OperationMode.ECO_CHARGE
elif ecomode.is_eco_discharge_mode():
elif eco_mode.is_eco_discharge_mode():
return OperationMode.ECO_DISCHARGE
else:
return OperationMode.ECO
Expand Down
13 changes: 9 additions & 4 deletions goodwe/et.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,18 @@ async def get_operation_modes(self, include_emulated: bool) -> Tuple[OperationMo
return tuple(result)

async def get_operation_mode(self) -> OperationMode:
mode = OperationMode(await self.read_setting('work_mode'))
mode_id = await self.read_setting('work_mode')
try:
mode = OperationMode(mode_id)
except ValueError:
logger.debug("Unknown work_mode value %d", mode_id)
return None
if OperationMode.ECO != mode:
return mode
ecomode = await self.read_setting('eco_mode_1')
if ecomode.is_eco_charge_mode():
eco_mode = await self.read_setting('eco_mode_1')
if eco_mode.is_eco_charge_mode():
return OperationMode.ECO_CHARGE
elif ecomode.is_eco_discharge_mode():
elif eco_mode.is_eco_discharge_mode():
return OperationMode.ECO_DISCHARGE
else:
return OperationMode.ECO
Expand Down

0 comments on commit 0feabc4

Please sign in to comment.