Skip to content

Commit

Permalink
fixed error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
escomputers committed Mar 26, 2023
1 parent a7bd1df commit 49aa4f5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sensors/bme280/air-temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import board
from adafruit_bme280 import basic as adafruit_bme280
import syslog
import datetime

syslog.openlog(facility=syslog.LOG_LOCAL0)

Expand All @@ -19,7 +18,7 @@ def sensing():
# GET & SEND AIR TEMPERATURE
air_temperature = str(("%.2f" % round(bme280.temperature, 2)))
try:
requests.post('http://localhost:8123/api/states/sensor.air_temperature', headers={
response = requests.post('http://localhost:8123/api/states/sensor.air_temperature', headers={
'Authorization': 'Bearer ' + LLA_TOKEN,
'Content-Type': 'application/json'
}, json={
Expand All @@ -28,8 +27,8 @@ def sensing():
'unit_of_measurement': '°C'
}
})
except ConnectionError:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
syslog.syslog(syslog.LOG_WARNING, '[' + timestamp + ']' + '[WARNING HASSIO REST API for BME280-AIRTEMP] Cannot send sensor data to Home Assistant REST endpoint.')
response.raise_for_status()
except requests.exceptions.RequestException as e:
syslog.syslog(syslog.LOG_WARNING, str(e))

sensing()

0 comments on commit 49aa4f5

Please sign in to comment.