Skip to content

Commit f70e6fa

Browse files
authored
Merge pull request #1 from adafruit/fix-protocol
Fix TOML not loading properly
2 parents e0dfe57 + 08f0758 commit f70e6fa

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

fake_bme280/basic.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
https://circuitpython.org/downloads
2727
"""
2828
import math
29-
import os
3029
import socket as pool
3130
import ssl
3231
import typing # pylint: disable=unused-import
32+
import toml
3333
from micropython import const
3434
import adafruit_requests
3535
from fake_bme280.protocol import I2C_Impl, SPI_Impl
@@ -75,17 +75,19 @@
7575
_BME280_REGISTER_TEMPDATA = const(0xFA)
7676
_BME280_REGISTER_HUMIDDATA = const(0xFD)
7777

78+
# Load the settings.toml file
79+
toml_config = toml.load("settings.toml")
80+
7881
# OpenWeatherMap API
7982
# GET weather data for a specific location
80-
# TODO: this could be cleaned up a bit..
8183
DATA_SOURCE = (
8284
"http://api.openweathermap.org/data/2.5/weather?q="
83-
+ os.getenv("openweather_location")
85+
+ toml_config["openweather_location"]
8486
+ "&units="
85-
+ os.getenv("openweather_units")
87+
+ toml_config["openweather_units"]
8688
+ "&mode=json"
8789
+ "&appid="
88-
+ os.getenv("openweather_token")
90+
+ toml_config["openweather_token"]
8991
)
9092

9193

@@ -113,11 +115,6 @@ def __init__(self, bus_implementation: typing.Union[I2C_Impl, SPI_Impl]) -> None
113115
self.sea_level_pressure = 1013.25
114116
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
115117
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-
)
121118
# Configure a CPython adafruit_requests session
122119
self.requests = adafruit_requests.Session(pool, ssl.create_default_context())
123120
self._current_forcast = None

fake_bme280/protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
class I2C_Impl:
1111
"Protocol implementation for the I2C bus."
1212

13-
# pylint: disable=too-few-public-methods
13+
# pylint: disable=too-few-public-methods, unused-argument, unused-import
1414
def __init__(self, i2c: I2C, address: int) -> None:
1515
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
1616
i2c_device,
1717
)
1818

19-
self._i2c = i2c_device.I2CDevice(i2c, address)
19+
# self._i2c = i2c_device.I2CDevice(i2c, address)
2020

2121

2222
class SPI_Impl:

0 commit comments

Comments
 (0)