Skip to content

Commit

Permalink
Various fixes & disable connection check in setup (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsK1 committed Oct 7, 2024
1 parent 749892d commit 9787f2e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 46 deletions.
77 changes: 46 additions & 31 deletions custom_components/solvis_control/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ def get_solvis_modules(data: ConfigType) -> Schema:
)


def get_solvis_modules_options(data: ConfigType) -> Schema:
return vol.Schema(
{
vol.Required(CONF_OPTION_1, default=data.get(CONF_OPTION_1)): bool, # HKR 2
vol.Required(CONF_OPTION_2, default=data.get(CONF_OPTION_2)): bool, # HKR 3
vol.Required(
CONF_OPTION_3, default=data.get(CONF_OPTION_3)
): bool, # solar collectors
vol.Required(
CONF_OPTION_4, default=data.get(CONF_OPTION_4)
): bool, # heat pump
}
)


def get_host_schema_options(data: ConfigType) -> Schema:
return vol.Schema(
{
Expand All @@ -72,23 +87,23 @@ async def async_step_user(
errors = {}
if user_input is not None:
self.data = user_input
try:
self.client = ModbusClient.AsyncModbusTcpClient(
user_input[CONF_HOST], user_input[CONF_PORT]
)
await self.client.connect()
# Perform a simple read to check the connection
await self.client.read_input_registers(32770, 1, 1)
except (ConnectionException, ModbusException) as exc:
_LOGGER.error(f"Modbus connection failed: {exc}")
errors["base"] = "cannot_connect"
else:
await self.client.close()
await self.async_set_unique_id(
self.data[CONF_HOST], raise_on_progress=False
)
self._abort_if_unique_id_configured()
return await self.async_step_features()
# try:
# self.client = ModbusClient.AsyncModbusTcpClient(
# user_input[CONF_HOST], user_input[CONF_PORT]
# )
# await self.client.connect()
# # Perform a simple read to check the connection
# await self.client.read_holding_registers(2818, 1, 1)
# except (ConnectionException, ModbusException) as exc:
# _LOGGER.error(f"Modbus connection failed: {exc}")
# errors["base"] = "cannot_connect"
# else:
# await self.client.close()
# await self.async_set_unique_id(
# self.data[CONF_HOST], raise_on_progress=False
# )
self._abort_if_unique_id_configured()
return await self.async_step_features()

return self.async_show_form(
step_id="user", data_schema=get_host_schema_config(self.data), errors=errors
Expand Down Expand Up @@ -131,19 +146,19 @@ async def async_step_init(
errors = {}
if user_input is not None:
self.data = user_input
try:
self.client = ModbusClient.AsyncModbusTcpClient(
user_input[CONF_HOST], user_input[CONF_PORT]
)
await self.client.connect()
# Perform a simple read to check the connection
await self.client.read_input_registers(32770, 1, 1)
except (ConnectionException, ModbusException) as exc:
_LOGGER.error(f"Modbus connection failed: {exc}")
errors["base"] = "cannot_connect"
else:
await self.client.close()
return await self.async_step_features()
# try:
# self.client = ModbusClient.AsyncModbusTcpClient(
# user_input[CONF_HOST], user_input[CONF_PORT]
# )
# await self.client.connect()
# # Perform a simple read to check the connection
# await self.client.read_holding_registers(2818, 1, 1)
# except (ConnectionException, ModbusException) as exc:
# _LOGGER.error(f"Modbus connection failed: {exc}")
# errors["base"] = "cannot_connect"
# else:
# await self.client.close()
return await self.async_step_features()

return self.async_show_form(
step_id="init",
Expand All @@ -157,7 +172,7 @@ async def async_step_features(
"""Handle the feature step."""
if user_input is None:
return self.async_show_form(
step_id="features", data_schema=get_solvis_modules(self.data)
step_id="features", data_schema=get_solvis_modules_options(self.data)
)
self.data.update(user_input)
return self.async_create_entry(title=self.config.get(CONF_NAME), data=self.data)
8 changes: 4 additions & 4 deletions custom_components/solvis_control/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
CONF_HOST = "host"
CONF_PORT = "port"
# Option attributes to make certain values configurable
CONF_OPTION_1 = False # HKR 2
CONF_OPTION_2 = False # HKR 3
CONF_OPTION_3 = False # Solar collector
CONF_OPTION_4 = False # heat pump
CONF_OPTION_1 = "HKR2" # HKR 2
CONF_OPTION_2 = "HKR3" # HKR 3
CONF_OPTION_3 = "solar collector" # Solar collector
CONF_OPTION_4 = "heat pump" # heat pump

DATA_COORDINATOR = "coordinator"
MANUFACTURER = "Solvis"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solvis_control/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def _async_update_data(self):
self.logger.debug("Polling data")

parsed_data: dict = {}
entity_registry = self.hass.data['entity_registry']
entity_registry = self.hass.data["entity_registry"]

try:
await self.modbus.connect()
Expand Down
11 changes: 6 additions & 5 deletions custom_components/solvis_control/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
"init":{
"data":{
"host":"IP-Adresse oder Hostname",
"port":"Port"
"port":"Port",
"cannot_connect": "Ein Fehler bei der Verbindung ist aufgetreten."
}
},
"features":{
"data":{
"CONF_OPTION_1":"HKR 2",
"CONF_OPTION_2":"HKR 3",
"CONF_OPTION_3":"Solar Kollektoren",
"CONF_OPTION_4":"Wärmepumpe"
"hkr2":"HKR 2",
"hkr3":"HKR 3",
"solar collector":"Solar Kollektoren",
"heat pump":"Wärmepumpe"
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions custom_components/solvis_control/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
"init":{
"data":{
"host":"IP-Adresse oder Hostname",
"port":"Port"
"port":"Port",
"cannot_connect": "Ein Fehler bei der Verbindung ist aufgetreten."
}
},
"features":{
"data":{
"CONF_OPTION_1":"HKR 2",
"CONF_OPTION_2":"HKR 3",
"CONF_OPTION_3":"Solar Kollektoren",
"CONF_OPTION_4":"Wärmepumpe"
"hkr2":"HKR 2",
"hkr3":"HKR 3",
"solar collector":"Solar Kollektoren",
"heat pump":"Wärmepumpe"
}
}
}
Expand Down

0 comments on commit 9787f2e

Please sign in to comment.