From 408cda0aff09ea79eba54718e4c6508a6d3d2278 Mon Sep 17 00:00:00 2001 From: Rick Rongen Date: Thu, 27 Aug 2020 17:22:10 +0200 Subject: [PATCH] feat: check if environ exists --- control/pca9685/pca9685.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/control/pca9685/pca9685.py b/control/pca9685/pca9685.py index ed7c371..1909fd1 100644 --- a/control/pca9685/pca9685.py +++ b/control/pca9685/pca9685.py @@ -17,6 +17,9 @@ import math import os +MOCK_ENV = 'PCA9685_MOCK_SMBUS' + + class MockSMBus: def __init__(self, bus_number): self.bus_number = bus_number @@ -72,7 +75,7 @@ class PWM: self.bus_number = 1 else: self.bus_number = bus_number - if os.environ['PCA9685_MOCK_SMBUS'] == 'true': + if MOCK_ENV in os.environ and os.environ[MOCK_ENV] == 'true': self.bus = MockSMBus(self.bus_number) else: self.bus = SMBus(self.bus_number)