diff --git a/main.py b/main.py index 4591f22..d75ba3e 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ from net import templates from net import util from net.config import config from sensors import MCP9808 +from sensors import SimulatedMCP9808 from sensors import WaterSensor @@ -18,8 +19,13 @@ class SensorServer(Server): def __init__(self): super().__init__() + + try: + self.mcp = MCP9808(I2C(0)) + except: + self.mcp = SimulatedMCP9808(temperature=37) + self.waterSensor = WaterSensor(0) - self.mcp = MCP9808(I2C(0)) self.aio = AdafruitIO() self.ntfy = Ntfy() self.ntp_interval_in_seconds = 60 * 60 diff --git a/sensors/__init__.py b/sensors/__init__.py index af4d296..a86aaf7 100644 --- a/sensors/__init__.py +++ b/sensors/__init__.py @@ -1,2 +1,3 @@ from .mcp9808 import MCP9808 +from .mcp9808 import SimulatedMCP9808 from .watersensor import WaterSensor diff --git a/sensors/mcp9808.py b/sensors/mcp9808.py index 6b3c38c..78ebbf4 100644 --- a/sensors/mcp9808.py +++ b/sensors/mcp9808.py @@ -251,3 +251,12 @@ class MCP9808(object): part = 0 if i > 7 else 1 value = 1 if (cfg[part] & (2**(i % 8))) > 0 else 0 print(meanings[i][0] + ": " + meanings[i][1 + value]) + + +class SimulatedMCP9808(): + + def __init__(self, temperature): + self.temperature = temperature + + def get_temp(self): + return self.temperature