Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pho3niX90 committed Feb 16, 2025
2 parents b0a64c2 + 5ea890c commit 7c857e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 9 additions & 7 deletions custom_components/solis_modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
)


async def async_setup(hass: HomeAssistant, entry: ConfigEntry):
async def async_setup(hass: HomeAssistant):
"""Set up the Modbus integration."""

def service_write_holding_register(call: ServiceCall):
address = call.data.get('address')
value = call.data.get('value')
host = entry.data.get("host")
controller = hass.data[DOMAIN][CONTROLLER][host]
# Perform the logic to write to the holding register using register_address and value_to_write
# ...
hass.create_task(controller.write_holding_register(address, value))
host = call.data.get("host")

if host:
controller = hass.data[DOMAIN][CONTROLLER][host]
hass.create_task(controller.write_holding_register(address, value))
else:
for controller in hass.data[DOMAIN][CONTROLLER]:
hass.create_task(controller.write_holding_register(address, value))

hass.services.async_register(
DOMAIN, "solis_write_holding_register", service_write_holding_register, schema=SCHEME_HOLDING_REGISTER
Expand All @@ -51,7 +54,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

host = entry.data.get("host")
port = entry.data.get("port", 502)

poll_interval = entry.data.get("poll_interval")

if poll_interval is None or poll_interval < 5:
Expand Down
6 changes: 2 additions & 4 deletions custom_components/solis_modbus/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,14 @@ def is_on(self):
def turn_on(self, **kwargs: Any) -> None:
_LOGGER.debug(f"{self._register}-{self._bit_position} turn on called ")
if self._register == 5:
self._modbus_controller.enabled = True
self._modbus_controller.connect()
self._modbus_controller.enable_connection()
else:
self.set_register_bit(True)

def turn_off(self, **kwargs: Any) -> None:
_LOGGER.debug(f"{self._register}-{self._bit_position} turn off called ")
if self._register == 5:
self._modbus_controller.enabled = False
self._modbus_controller.disconnect()
self._modbus_controller.disable_connection()
else:
self.set_register_bit(False)

Expand Down

0 comments on commit 7c857e7

Please sign in to comment.