-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
213 lines (151 loc) · 6.3 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python3
# vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab
#########################################################################
# Copyright 2022- Michael Wenzel [email protected]
#########################################################################
# This file is part of SmartHomeNG.
# https://www.smarthomeNG.de
# https://knx-user-forum.de/forum/supportforen/smarthome-py
#
# Plugin to connect to Foshk / Ecowitt Weather Gateway.
#
# SmartHomeNG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SmartHomeNG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SmartHomeNG. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
# ============================================================================
# Config classes
# ============================================================================
from dataclasses import dataclass, field
@dataclass
class GatewayConfig:
"""Class to simplify use and handling of gateway config."""
# known device models
known_models: set = ('GW1000', 'GW1100', 'GW2000', 'WH2650', 'WH2680', 'WN1900', 'GW1200', 'WS3800', 'WS3900', 'WS3910')
# models supporting get-request
known_models_with_get_request: set = ('GW1100', 'GW2000')
# sensor with separate firmware
sensors_with_firmware: dict = field(default_factory=lambda: {'wh80': 'WS80', 'wh85': 'WS85', 'wh90': 'WS90'})
# Gateway IP for api communication
ip_address: str = None
# Gateway port for api communication
port: int = 45000
# Gateway mac address
mac: str = None
# Gateway model
model: str = None
# network broadcast address - the address that network broadcasts are sent to
broadcast_address: str = '255.255.255.255'
# network broadcast port - the port that network broadcasts are sent to
broadcast_port: int = 46000
# default socket timeout in sec
socket_timeout: int = 2
# default request timeout in sec
request_timeout: int = 2
# default broadcast timeout in sec
broadcast_timeout: int = 5
# default discovery method, may be 'api' or 'broadcast'
discovery_method: str = 'broadcast'
# default port to use for discovery of devices by broadcast monitoring
discovery_port = 59387
# default period in seconds to use for discovery of devices by broadcast monitoring
discovery_period = 5
# default retry/wait time in sec
retry_wait: int = 10
# default max tries when polling the API
max_tries: int = 3
# When run as a service the default age in seconds after which API data is considered stale and will not be used to augment loop packets
max_age: int = 60
# default device poll interval in sec via api
api_data_cycle: int = 20
# default device poll crontab via api
api_data_crontab: str = None
# default period between lost contact log entries during an extended period of lost contact when run as a Service in sec
lost_contact_log_period: int = 21600
# default battery state filtering
show_battery: bool = False
# default firmware update check interval in sec
fw_check_crontab: str = None
# show availability of firmware update
show_fw_update_available: bool = False
# availability of firmware update
fw_update_available: bool = False
# log unknown fields
log_unknown_fields: bool = False
# create a separate field for summarized battery warning
show_battery_warning: bool = True
# create a separate field for summarized sensor warning
show_sensor_warning: bool = True
# create a separate field for strom warning
show_storm_warning: bool = True
# create a separate field for weatherstation warning
show_weatherstation_warning: bool = True
# create a separate field for leakage warning
show_leakage_warning: bool = True
# is WH32 in use
use_wh32: bool = True
# is WH24 attached
is_wh24: bool = False
# should WH40 batt be ignored
ignore_wh40_batt: bool = True
# is a legacy wh40 sensor connected
legacy_wh40: bool = False
# ip-address of http server for uploading ecowitt protocol
post_server_ip: str = None
# port of http server for uploading ecowitt protocol
post_server_port: int = None
# data cycle for uploading ecowitt protocol
post_server_cycle: int = None
# usr path for data server upload
usr_path: str = None
# custom params for data server upload
custom_params: dict = None
# postion of local installation
lat: float = None
lon: float = None
alt: float = None
# language of installation
lang: str = 'de'
# Firmware Update URL String
FW_UPDATE_URL: str = 'http://download.ecowitt.net/down/filewave?v=FirwaveReadme.txt'.replace("\"", "")
def __post_init__(self):
if self.fw_check_crontab is not None:
self.show_fw_update_available = True
@dataclass
class DebugLogConfig:
"""Class to define debug log options gateway config."""
main_class: bool = False
gateway: bool = True
api: bool = True
tcp: bool = True
http: bool = True
@dataclass
class WarningLevels:
# Druckunterschied in 1h zur Auslösung der Sturmwarnung: 1.75hPa
STORM_WARNDIFF_1H: float = 1.75
# Druckunterschied in 3h zur Auslösung der Sturmwarnung: 3.75hPa
STORM_WARNDIFF_3H: float = 3.75
# Auflauf der Sturmwarnung: 60 Minuten
STORM_EXPIRE: int = 60
# Auslösen der Gewitterwarnung nach: 1 Blitz
TSTORM_WARNCOUNT: int = 1
# Auslösen der Gewitterwarnung bei Gewitterabstand: 30km
TSTORM_WARNDIST: int = 30
# Auflauf der Gewitterwarnung: 15 Minuten
TSTORM_EXPIRE: int = 15
# Auslösen der CO2 Warnung: ab 1200
CO2_WARNLEVEL: int = 1200
# Minimal Sonne
SUN_MIN: float = 0
# Sonnenkoeffizient
SUN_COEF: float = 0.8