Skip to content

Commit

Permalink
Merge pull request #1 from mihaigalos/master
Browse files Browse the repository at this point in the history
fix: SSL - Always defaulting to https
  • Loading branch information
dbsqp authored Sep 29, 2024
2 parents 3b529cd + 2dab553 commit f1f212f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y \
rm -rf /var/lib/apt/lists/*

# RUN pip install setuptools
RUN pip3 install pytz influxdb-client requests lnetatmo
RUN pip3 install --break-system-packages pytz influxdb-client requests lnetatmo

# Environment vars
ENV PYTHONIOENCODING=utf-8
Expand Down
46 changes: 30 additions & 16 deletions netatmo2influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
influxdb2_ssl_verify = influxdb2_ssl_verify_str.lower() == "true"
else:
influxdb2_ssl_verify = False

# hard encoded environment variables!

# report debug status
if debug:
print ( " debug: TRUE" )
else:
print ( " debug: FALSE" )
print ( " debug: FALSE" )
if influxdb2_ssl:
print ( " SSL: TRUE" )
else:
Expand All @@ -73,7 +73,7 @@


# influxDBv2
if influxdb2_ssl_str:
if influxdb2_ssl:
influxdb2_url="https://" + influxdb2_host + ":" + str(influxdb2_port)
else:
influxdb2_url="http://" + influxdb2_host + ":" + str(influxdb2_port)
Expand Down Expand Up @@ -103,11 +103,11 @@


# pass data to InfluxDB
def send_data(ds):
def send_data(ds):
senddata={}
dd=ds['dashboard_data']
time = dd['time_utc']
timeOut = datetime.datetime.fromtimestamp(time).strftime("%Y-%m-%dT%H:%M:%SZ")
timeOut = datetime.datetime.fromtimestamp(time).strftime("%Y-%m-%dT%H:%M:%SZ")

# pass module data
for key in ds:
Expand All @@ -119,16 +119,16 @@ def send_data(ds):
if key == 'battery_percent':
measurement="battery"
time=ds['last_seen']

if key == "rf_status":
measurement="signal"
time=ds['last_seen']

if key == "wifi_status":
measurement="signal"
time=ds['last_status_store']
timeOut = datetime.datetime.fromtimestamp(time).strftime("%Y-%m-%dT%H:%M:%SZ")

timeOut = datetime.datetime.fromtimestamp(time).strftime("%Y-%m-%dT%H:%M:%SZ")

senddata["measurement"]=measurement
senddata["time"]=timeOut
Expand All @@ -154,13 +154,13 @@ def send_data(ds):
#if key in keylist:
value=round(float(dd[key]),2)
#else:
# value=dd[key]
# value=dd[key]

if ds['module_name'] == "Wind":
senddata["measurement"]="wind"
else:
senddata["measurement"]=key.lower()

senddata["time"]=timeOut
senddata["tags"]={}
senddata["tags"]["source"]="docker netatmo-influxdbv2"
Expand All @@ -186,19 +186,19 @@ def send_data(ds):

if key == "Rain":
senddata["fields"]["mm"]=value

if key == "WindStrength":
senddata["fields"]["speed"]=value
senddata["tags"]["type"]="general"

if key == "WindAngle":
senddata["fields"]["direction"]=value
senddata["tags"]["type"]="general"

if key == "GustStrength":
senddata["fields"]["speed"]=value
senddata["tags"]["type"]="gust"

if key == "GustAngle":
senddata["fields"]["direction"]=value
senddata["tags"]["type"]="gust"
Expand All @@ -209,6 +209,20 @@ def send_data(ds):
write_api.write(bucket=influxdb2_bucket, org=influxdb2_org, record=[senddata])


def modulesNamesList(o, station=None):
s = o.getStation(station)
if not s: raise NoDevice("No station with name or id %s" % station)
o.default_station = station
o.default_station_data = s
o.modules = dict()
if 'modules' in o.default_station_data:
for m in o.default_station_data['modules']:
o.modules[ m['_id'] ] = m
res = [m['module_name'] for m in o.modules.values()]
#res.append(station['module_name'])
return res


# pass default station
ds=devList.stationByName(devList.default_station)

Expand All @@ -230,7 +244,7 @@ def send_data(ds):


# pass modules
for name in devList.modulesNamesList( station='devList.default_station' ):
for name in modulesNamesList(devList, ds['station_name'] ):
ds=devList.moduleByName(name)
if ds is None:
continue
Expand Down

0 comments on commit f1f212f

Please sign in to comment.