Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
fix read an write
  • Loading branch information
CrazyUs3r authored Jul 5, 2024
1 parent 8ad860a commit bae1763
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ async def async_get(self, runtime = 0):
return self.get_result()

# Service calls
async def service_read_holding_register(self, register, value):
_LOGGER.debug(f'Service Call: read_holding_registers : [{register}], value : [{value}]')
try:
await self.async_connect()
await self.read_holding_registers(register, value)
except Exception as e:
_LOGGER.warning(f"Service Call: read_holding_registers : [{register}], value : [{value}] failed. [{format_exception(e)}]")
await self.async_disconnect()
return

async def service_read_multiple_holding_registers(self, register, values):
_LOGGER.debug(f'Service Call: read_multiple_holding_registers: [{register}], values : [{values}]')
try:
await self.async_connect()
await self.read_multiple_holding_registers(register, values)
except Exception as e:
_LOGGER.warning(f"Service Call: read_multiple_holding_registers: [{register}], values : [{values}] failed. [{format_exception(e)}]")
await self.async_disconnect()
return

async def service_write_holding_register(self, register, value):
_LOGGER.debug(f'Service Call: write_holding_register : [{register}], value : [{value}]')
try:
Expand All @@ -246,3 +266,4 @@ async def service_write_multiple_holding_registers(self, register, values):
_LOGGER.warning(f"Service Call: write_multiple_holding_registers: [{register}], values : [{values}] failed. [{format_exception(e)}]")
await self.async_disconnect()
return

0 comments on commit bae1763

Please sign in to comment.