Skip to content

Commit d7d73ed

Browse files
.
1 parent 68fd8a2 commit d7d73ed

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/sml2mqtt/config/inputs.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class HttpSourceSettings(SmlSourceSettingsBase):
8484
user: str = Field(default='', description='User (if needed)')
8585
password: str = Field(default='', description='Password (if needed)')
8686

87+
request_timeout: StrictInt | StrictFloat | None = Field(
88+
default=None, alias='request timeout', description='Dedicated timeout for the http request',
89+
in_file=False
90+
)
91+
8792
@override
8893
def get_device_name(self) -> str:
8994
return self.url.host
@@ -102,4 +107,8 @@ def check_timeout_gt_interval(self):
102107
return self
103108

104109
def get_request_timeout(self) -> ClientTimeout:
105-
return ClientTimeout(self.interval)
110+
value = self.interval if self.request_timeout is None else self.request_timeout
111+
if value is None:
112+
msg = 'No value for ClientTimeout'
113+
raise ValueError(msg)
114+
return ClientTimeout(total=value)

src/sml2mqtt/sml_source/http.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ async def _http_task(self) -> None:
102102
com_errors += 1
103103
max_ignore: int = 7
104104
if com_errors <= max_ignore:
105-
# errors: 1, 2, 3, 4, 5, 6, 7, 8, ...
106-
# factor: 0.5, 1.1, 2.1, 3.6, 5.5, 8.1, 11.1, 14.5, ...
107-
# With 0.8 x interval we can do the first three retries without going into timeout
108-
interval = (((com_errors - 0.5) ** 2) / 4 + 0.5) * (self.interval * 0.8)
105+
# errors: 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
106+
# factor: 0.4, 0.9, 1.9, 3.4, 5.4, 7.9, 10.9, 14.4, 18.4, ...
107+
interval = (((com_errors - 0.5) ** 2) / 4 + 0.3) * self.interval
109108
log.debug(f'Ignored {com_errors:d}/{max_ignore:d} {e}')
110109
continue
111110

0 commit comments

Comments
 (0)