|
26 | 26 | https://circuitpython.org/downloads |
27 | 27 | """ |
28 | 28 | import math |
29 | | -import os |
30 | 29 | import socket as pool |
31 | 30 | import ssl |
32 | 31 | import typing # pylint: disable=unused-import |
| 32 | +import toml |
33 | 33 | from micropython import const |
34 | 34 | import adafruit_requests |
35 | 35 | from fake_bme280.protocol import I2C_Impl, SPI_Impl |
|
75 | 75 | _BME280_REGISTER_TEMPDATA = const(0xFA) |
76 | 76 | _BME280_REGISTER_HUMIDDATA = const(0xFD) |
77 | 77 |
|
| 78 | +# Load the settings.toml file |
| 79 | +toml_config = toml.load("settings.toml") |
| 80 | + |
78 | 81 | # OpenWeatherMap API |
79 | 82 | # GET weather data for a specific location |
80 | | -# TODO: this could be cleaned up a bit.. |
81 | 83 | DATA_SOURCE = ( |
82 | 84 | "http://api.openweathermap.org/data/2.5/weather?q=" |
83 | | - + os.getenv("openweather_location") |
| 85 | + + toml_config["openweather_location"] |
84 | 86 | + "&units=" |
85 | | - + os.getenv("openweather_units") |
| 87 | + + toml_config["openweather_units"] |
86 | 88 | + "&mode=json" |
87 | 89 | + "&appid=" |
88 | | - + os.getenv("openweather_token") |
| 90 | + + toml_config["openweather_token"] |
89 | 91 | ) |
90 | 92 |
|
91 | 93 |
|
@@ -113,11 +115,6 @@ def __init__(self, bus_implementation: typing.Union[I2C_Impl, SPI_Impl]) -> None |
113 | 115 | self.sea_level_pressure = 1013.25 |
114 | 116 | """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" |
115 | 117 | self._t_fine = None |
116 | | - # Configure OpenWeather for mock data |
117 | | - self.openweather_token = os.getenv("OPENWEATHER_TOKEN", "default_token") |
118 | | - self.openweather_location = os.getenv( |
119 | | - "OPENWEATHER_LOCATION", "default_location" |
120 | | - ) |
121 | 118 | # Configure a CPython adafruit_requests session |
122 | 119 | self.requests = adafruit_requests.Session(pool, ssl.create_default_context()) |
123 | 120 | self._current_forcast = None |
|
0 commit comments