Skip to content

Commit 9787f2e

Browse files
committed
Various fixes & disable connection check in setup (for now)
1 parent 749892d commit 9787f2e

File tree

5 files changed

+63
-46
lines changed

5 files changed

+63
-46
lines changed

custom_components/solvis_control/config_flow.py

+46-31
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ def get_solvis_modules(data: ConfigType) -> Schema:
4646
)
4747

4848

49+
def get_solvis_modules_options(data: ConfigType) -> Schema:
50+
return vol.Schema(
51+
{
52+
vol.Required(CONF_OPTION_1, default=data.get(CONF_OPTION_1)): bool, # HKR 2
53+
vol.Required(CONF_OPTION_2, default=data.get(CONF_OPTION_2)): bool, # HKR 3
54+
vol.Required(
55+
CONF_OPTION_3, default=data.get(CONF_OPTION_3)
56+
): bool, # solar collectors
57+
vol.Required(
58+
CONF_OPTION_4, default=data.get(CONF_OPTION_4)
59+
): bool, # heat pump
60+
}
61+
)
62+
63+
4964
def get_host_schema_options(data: ConfigType) -> Schema:
5065
return vol.Schema(
5166
{
@@ -72,23 +87,23 @@ async def async_step_user(
7287
errors = {}
7388
if user_input is not None:
7489
self.data = user_input
75-
try:
76-
self.client = ModbusClient.AsyncModbusTcpClient(
77-
user_input[CONF_HOST], user_input[CONF_PORT]
78-
)
79-
await self.client.connect()
80-
# Perform a simple read to check the connection
81-
await self.client.read_input_registers(32770, 1, 1)
82-
except (ConnectionException, ModbusException) as exc:
83-
_LOGGER.error(f"Modbus connection failed: {exc}")
84-
errors["base"] = "cannot_connect"
85-
else:
86-
await self.client.close()
87-
await self.async_set_unique_id(
88-
self.data[CONF_HOST], raise_on_progress=False
89-
)
90-
self._abort_if_unique_id_configured()
91-
return await self.async_step_features()
90+
# try:
91+
# self.client = ModbusClient.AsyncModbusTcpClient(
92+
# user_input[CONF_HOST], user_input[CONF_PORT]
93+
# )
94+
# await self.client.connect()
95+
# # Perform a simple read to check the connection
96+
# await self.client.read_holding_registers(2818, 1, 1)
97+
# except (ConnectionException, ModbusException) as exc:
98+
# _LOGGER.error(f"Modbus connection failed: {exc}")
99+
# errors["base"] = "cannot_connect"
100+
# else:
101+
# await self.client.close()
102+
# await self.async_set_unique_id(
103+
# self.data[CONF_HOST], raise_on_progress=False
104+
# )
105+
self._abort_if_unique_id_configured()
106+
return await self.async_step_features()
92107

93108
return self.async_show_form(
94109
step_id="user", data_schema=get_host_schema_config(self.data), errors=errors
@@ -131,19 +146,19 @@ async def async_step_init(
131146
errors = {}
132147
if user_input is not None:
133148
self.data = user_input
134-
try:
135-
self.client = ModbusClient.AsyncModbusTcpClient(
136-
user_input[CONF_HOST], user_input[CONF_PORT]
137-
)
138-
await self.client.connect()
139-
# Perform a simple read to check the connection
140-
await self.client.read_input_registers(32770, 1, 1)
141-
except (ConnectionException, ModbusException) as exc:
142-
_LOGGER.error(f"Modbus connection failed: {exc}")
143-
errors["base"] = "cannot_connect"
144-
else:
145-
await self.client.close()
146-
return await self.async_step_features()
149+
# try:
150+
# self.client = ModbusClient.AsyncModbusTcpClient(
151+
# user_input[CONF_HOST], user_input[CONF_PORT]
152+
# )
153+
# await self.client.connect()
154+
# # Perform a simple read to check the connection
155+
# await self.client.read_holding_registers(2818, 1, 1)
156+
# except (ConnectionException, ModbusException) as exc:
157+
# _LOGGER.error(f"Modbus connection failed: {exc}")
158+
# errors["base"] = "cannot_connect"
159+
# else:
160+
# await self.client.close()
161+
return await self.async_step_features()
147162

148163
return self.async_show_form(
149164
step_id="init",
@@ -157,7 +172,7 @@ async def async_step_features(
157172
"""Handle the feature step."""
158173
if user_input is None:
159174
return self.async_show_form(
160-
step_id="features", data_schema=get_solvis_modules(self.data)
175+
step_id="features", data_schema=get_solvis_modules_options(self.data)
161176
)
162177
self.data.update(user_input)
163178
return self.async_create_entry(title=self.config.get(CONF_NAME), data=self.data)

custom_components/solvis_control/const.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
CONF_HOST = "host"
77
CONF_PORT = "port"
88
# Option attributes to make certain values configurable
9-
CONF_OPTION_1 = False # HKR 2
10-
CONF_OPTION_2 = False # HKR 3
11-
CONF_OPTION_3 = False # Solar collector
12-
CONF_OPTION_4 = False # heat pump
9+
CONF_OPTION_1 = "HKR2" # HKR 2
10+
CONF_OPTION_2 = "HKR3" # HKR 3
11+
CONF_OPTION_3 = "solar collector" # Solar collector
12+
CONF_OPTION_4 = "heat pump" # heat pump
1313

1414
DATA_COORDINATOR = "coordinator"
1515
MANUFACTURER = "Solvis"

custom_components/solvis_control/coordinator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def _async_update_data(self):
5454
self.logger.debug("Polling data")
5555

5656
parsed_data: dict = {}
57-
entity_registry = self.hass.data['entity_registry']
57+
entity_registry = self.hass.data["entity_registry"]
5858

5959
try:
6060
await self.modbus.connect()

custom_components/solvis_control/strings.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
"init":{
1313
"data":{
1414
"host":"IP-Adresse oder Hostname",
15-
"port":"Port"
15+
"port":"Port",
16+
"cannot_connect": "Ein Fehler bei der Verbindung ist aufgetreten."
1617
}
1718
},
1819
"features":{
1920
"data":{
20-
"CONF_OPTION_1":"HKR 2",
21-
"CONF_OPTION_2":"HKR 3",
22-
"CONF_OPTION_3":"Solar Kollektoren",
23-
"CONF_OPTION_4":"Wärmepumpe"
21+
"hkr2":"HKR 2",
22+
"hkr3":"HKR 3",
23+
"solar collector":"Solar Kollektoren",
24+
"heat pump":"Wärmepumpe"
2425
}
2526
}
2627
}

custom_components/solvis_control/translations/de.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
"init":{
1313
"data":{
1414
"host":"IP-Adresse oder Hostname",
15-
"port":"Port"
15+
"port":"Port",
16+
"cannot_connect": "Ein Fehler bei der Verbindung ist aufgetreten."
1617
}
1718
},
1819
"features":{
1920
"data":{
20-
"CONF_OPTION_1":"HKR 2",
21-
"CONF_OPTION_2":"HKR 3",
22-
"CONF_OPTION_3":"Solar Kollektoren",
23-
"CONF_OPTION_4":"Wärmepumpe"
21+
"hkr2":"HKR 2",
22+
"hkr3":"HKR 3",
23+
"solar collector":"Solar Kollektoren",
24+
"heat pump":"Wärmepumpe"
2425
}
2526
}
2627
}

0 commit comments

Comments
 (0)