Skip to content

Commit

Permalink
Add support for generic modbus setting read
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 10, 2024
1 parent 5ba0d18 commit d410da1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions goodwe/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ async def read_runtime_data(self) -> Dict[str, Any]:
return data

async def read_setting(self, setting_id: str) -> Any:
if setting_id.startswith("modbus"):
response = await self._read_from_socket(self._read_command(int(setting_id[7:]), 1))
return int.from_bytes(response.read(2), byteorder="big", signed=True)
setting = self._settings.get(setting_id)
if not setting:
raise ValueError(f'Unknown setting "{setting_id}"')
Expand Down
3 changes: 3 additions & 0 deletions goodwe/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ async def read_setting(self, setting_id: str) -> Any:
if not setting:
raise ValueError(f'Unknown setting "{setting_id}"')
return await self._read_setting(setting)
elif setting_id.startswith("modbus"):
response = await self._read_from_socket(self._read_command(int(setting_id[7:]), 1))
return int.from_bytes(response.read(2), byteorder="big", signed=True)
else:
all_settings = await self.read_settings_data()
return all_settings.get(setting_id)
Expand Down
3 changes: 3 additions & 0 deletions goodwe/et.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ async def read_runtime_data(self) -> Dict[str, Any]:
return data

async def read_setting(self, setting_id: str) -> Any:
if setting_id.startswith("modbus"):
response = await self._read_from_socket(self._read_command(int(setting_id[7:]), 1))
return int.from_bytes(response.read(2), byteorder="big", signed=True)
setting = self._settings.get(setting_id)
if not setting:
raise ValueError(f'Unknown setting "{setting_id}"')
Expand Down
3 changes: 3 additions & 0 deletions tests/test_et.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ def test_GW10K_ET_read_setting(self):
self.loop.run_until_complete(self.read_setting('time'))
self.assertEqual('f703b090000337b0', self.request.hex())

self.loop.run_until_complete(self.read_setting('modbus_47000'))
self.assertEqual('f703b798000136c7', self.request.hex())

def test_GW10K_ET_write_setting(self):
self.loop.run_until_complete(self.write_setting('grid_export_limit', 100))
self.assertEqual('f706b996006459c7', self.request.hex())
Expand Down

0 comments on commit d410da1

Please sign in to comment.