def test_max_sun_normal_input(self, mock_get_weight, mock_get_cc_et):
        mock_get_cc_et.return_value = (80, -10)
        mock_get_weight.return_value = 0.88
        self.assertAlmostEqual(heat_mgmt.heat_mgmt_algorithm(
            MockTemperatureSensor()),
                               42.48,
                               places=2)

        mock_get_cc_et.return_value = (80, -10)
        mock_get_weight.return_value = 0
        self.assertAlmostEqual(heat_mgmt.heat_mgmt_algorithm(
            MockTemperatureSensor()),
                               -20,
                               places=2)

        mock_get_cc_et.return_value = (80, -10)
        mock_get_weight.return_value = 1
        self.assertAlmostEqual(heat_mgmt.heat_mgmt_algorithm(
            MockTemperatureSensor()),
                               51,
                               places=2)

        mock_get_cc_et.return_value = (87, 22)
        mock_get_weight.return_value = 0.88
        self.assertAlmostEqual(heat_mgmt.heat_mgmt_algorithm(
            MockTemperatureSensor()),
                               -10,
                               places=2)
Example #2
0
 def test_getTemperature_with_exception(self):
     tempSensor = MockTemperatureSensor()
     tempSensor.getSample = MagicMock(side_effect=Exception)
     blindsSystem = SmartBlindsSystem(Blinds(None, None),
                                      BlindsSchedule(BlindMode.DARK),
                                      tempSensor)
     assert (blindsSystem.getTemperature()[1] == RESP_CODES["BAD_REQUEST"])
Example #3
0
    def test_comp_exception(self, mock_get_weight, mock_get_cc_et,
                            mock_get_solar_angle):
        mock_get_solar_angle.return_value = 810
        mock_get_cc_et.return_value = [80, -10]
        mock_get_weight.return_value = 0.88
        with self.assertRaises(exceptions.InputError):
            comp.composite_algorithm(MockTemperatureSensor())

        mock_get_solar_angle.return_value = 10
        mock_get_cc_et.return_value = [180, -10]
        mock_get_weight.return_value = 0.88
        with self.assertRaises(exceptions.InputError):
            comp.composite_algorithm(MockTemperatureSensor())
Example #4
0
 def test_comp_normal(self, mock_get_weight, mock_get_cc_et,
                      mock_get_solar_angle):
     mock_get_solar_angle.return_value = 80
     mock_get_cc_et.return_value = [80, -10]
     mock_get_weight.return_value = 0.88
     self.assertAlmostEqual(comp.composite_algorithm(
         MockTemperatureSensor()),
                            -65.3024,
                            places=4)
 def test_heat_mgmt_equil(self, mock_get_temp, mock_get_weight,
                          mock_get_cc_et):
     mock_get_cc_et.return_value = (87, 22)
     mock_get_weight.return_value = 0.88
     mock_get_temp.return_value = 22
     # in actuality motor should do nothing
     self.assertAlmostEqual(heat_mgmt.heat_mgmt_algorithm(
         MockTemperatureSensor()),
                            0,
                            places=0)
Example #6
0
app = Flask(__name__)
appFilePath = os.path.dirname(os.path.abspath(__file__))
cfg = DevelopmentConfig(
) if app.config["ENV"] == "development" else ProductionConfig()
app.config.from_object(cfg)

# set the users db for auth, irrespective of the dev/production config
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///' + \
    appFilePath + '/users.db'
CORS(app)

db = SQLAlchemy(app)

# INIT BLINDS SYSTEM RELATED COMPONENTS #
temp_sensor = BME280TemperatureSensor() if app.config["USE_TEMP_SENSOR"] \
    else MockTemperatureSensor()

# Init motor driver
STEP_PIN = 20
DIR_PIN = 21
ENABLE_PIN = 25
MS1_PIN = 24
MS2_PIN = 23

# Default User
DEFAULT_USER = "******"

# Guard imports behind config flag
# This ensures that server can be run in Docker container
if app.config["USE_MOTOR"]:
    import RPi.GPIO as rpigpio
 def test_max_sun_exception(self, mock_get_weight, mock_get_cc_et):
     mock_get_cc_et.return_value = (101, 0)
     mock_get_weight.return_value = 0.5
     with self.assertRaises(exceptions.InputError):
         heat_mgmt.heat_mgmt_algorithm(MockTemperatureSensor())
Example #8
0
 def blindsSystem(self):
     yield SmartBlindsSystem(Blinds(None, None),
                             BlindsSchedule(BlindMode.DARK),
                             MockTemperatureSensor())