Skip to content

Commit

Permalink
fix: The truth value of an array is ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 10, 2024
1 parent 2b67cd1 commit eb2a141
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions custom_components/solarman/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ async def read_holding_registers(call: ServiceCall) -> int:

register = call.data.get(SERVICES_PARAM_REGISTER)
quantity = call.data.get(SERVICES_PARAM_QUANTITY)
result = {}

try:
response = await inverter.call(CODE.READ_HOLDING_REGISTERS, register, quantity)
if (response := await inverter.call(CODE.READ_HOLDING_REGISTERS, register, quantity)) is not None:
for i in range(0, quantity):
result[register + i] = response[i]

except Exception as e:
raise ServiceValidationError(e, translation_domain = DOMAIN, translation_key = "call_failed")

result = {}

if response:
for i in range(0, quantity):
result[register + i] = response[i]

return result

async def read_input_registers(call: ServiceCall) -> int:
Expand All @@ -81,18 +79,16 @@ async def read_input_registers(call: ServiceCall) -> int:

register = call.data.get(SERVICES_PARAM_REGISTER)
quantity = call.data.get(SERVICES_PARAM_QUANTITY)
result = {}

try:
response = await inverter.call(CODE.READ_INPUT, register, quantity)
if (response := await inverter.call(CODE.READ_INPUT, register, quantity)) is not None:
for i in range(0, quantity):
result[register + i] = response[i]

except Exception as e:
raise ServiceValidationError(e, translation_domain = DOMAIN, translation_key = "call_failed")

result = {}

if response:
for i in range(0, quantity):
result[register + i] = response[i]

return result

async def write_holding_register(call: ServiceCall) -> None:
Expand All @@ -110,8 +106,6 @@ async def write_holding_register(call: ServiceCall) -> None:
except Exception as e:
raise ServiceValidationError(e, translation_domain = DOMAIN, translation_key = "call_failed")

return

async def write_multiple_holding_registers(call: ServiceCall) -> None:
_LOGGER.debug(f"write_multiple_holding_registers: {call}")

Expand All @@ -127,8 +121,6 @@ async def write_multiple_holding_registers(call: ServiceCall) -> None:
except Exception as e:
raise ServiceValidationError(e, translation_domain = DOMAIN, translation_key = "call_failed")

return

hass.services.async_register(
DOMAIN, SERVICE_READ_HOLDING_REGISTERS, read_holding_registers, schema = vol.Schema(HEADER_SCHEMA | QUANTITY_SCHEMA), supports_response = SupportsResponse.OPTIONAL
)
Expand Down

0 comments on commit eb2a141

Please sign in to comment.