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