Exemple #1
0
    def test_catches_exception_and_stops_pumps(self):
        self.sump.percentage_changed = Mock(
            side_effect=UnexpectedWaterLevel(100))
        controller = Controller(self.sump, self.scripts, self.configuration,
                                ProgressTracker())
        controller.water_change()

        sump_calls = [
            call.return_pump.off(),
            call.empty_pump.on(),
            call.percentage_changed(),
            call.refill_pump.off(),
            call.return_pump.off(),
            call.empty_pump.off()
        ]

        self.sump.assert_has_calls(sump_calls, any_order=False)
Exemple #2
0
    def test_executes_water_change(self):
        self.sump.percentage_changed = Mock(return_value=100)
        self.sump.get_state = Mock(return_value=(True, 100))
        self.sump.temperature_breakdown = Mock(return_value=([2, 3, 4],
                                                             [3, 4, 5], 1))

        controller = Controller(self.sump, self.scripts, self.configuration,
                                ProgressTracker())
        controller.water_change()

        sump_calls = [
            call.return_pump.off(),
            call.empty_pump.on(),
            call.percentage_changed(),
            call.empty_pump.off(),
            call.refill_pump.on(),
            call.get_state(),
            call.refill_pump.off(),
            call.temperature_breakdown(),
            call.return_pump.on()
        ]

        self.sump.assert_has_calls(sump_calls, any_order=False)
Exemple #3
0
        def wrapper(*args):
            progress_tracker = ProgressTracker()
            print("")
            progress_tracker.write_ln(
                f"{Style.YELLOW}{decorated.__name__} starting:")
            started = datetime.now()

            decorated(*args)

            ended = datetime.now()
            formatted_time = ended.strftime("%H:%M")
            interval = ended - started
            interval_minutes_seconds = divmod(interval.total_seconds(), 60)

            progress_tracker.write_ln(
                f"{Style.YELLOW}{decorated.__name__} complete: "
                f"{Style.BOLD}{Style.WHITE}{int(interval_minutes_seconds[0])}m "
                f"{int(interval_minutes_seconds[1])}s "
                f"{Style.RESET}{Style.YELLOW}at "
                f"{Style.BOLD}{Style.WHITE}{formatted_time} ")
global tank_temp_sensor
global sump_temp_sensor
tank_temp_sensor = TemperatureSensor("tank sensor", config.get("tank_temp_device_id"))
sump_temp_sensor = TemperatureSensor("sump sensor", config.get("sump_temp_device_id"))

num = 2
tank_temps = [round(tank_temp_sensor.get_temp(), 2) for _ in range(num)]
sump_temps = [round(sump_temp_sensor.get_temp(), 2) for _ in range(num)]

tank_temp_average = reduce(lambda x, y: (x + y), tank_temps) / num
sump_temp_average = reduce(lambda x, y: (x + y), sump_temps) / num

tank_average = f"{'{:.2f}'.format(tank_temp_average)}"
sump_average = f"{'{:.2f}'.format(sump_temp_average)}"
difference = f"{'{:.2f}'.format(abs(tank_temp_average - sump_temp_average))}"

date_time = datetime.now().strftime("%H:%M")
progress_tracker = ProgressTracker()

print("")
progress_tracker.write_ln(f"{Style.WHITE}{Style.BOLD}{date_time}: {Style.RESET}"
                          f"{Style.GREEN}tank temp:{Style.RESET}{Style.BOLD}{Style.WHITE} {tank_average}{Style.RESET}°c, "
                          f"{Style.GREEN}sump temp:{Style.RESET}{Style.BOLD}{Style.WHITE} {sump_average}{Style.RESET}°c, "
                          f"{Style.GREEN}difference:{Style.RESET}{Style.BOLD}{Style.WHITE} {difference}{Style.RESET}°c")

progress_tracker.write_ln(f"{Style.WHITE}{Style.BOLD}{date_time}: {Style.RESET}"
                          f"{Style.GREEN}tank temps: {Style.WHITE}{Style.BOLD}{tank_temps},{Style.RESET} "
                          f"{Style.GREEN}sump temps {Style.WHITE}{Style.BOLD}{sump_temps}{Style.RESET}")

#!/usr/bin/env python3
from datetime import datetime
from functools import reduce

from Progress import ProgressTracker, Style
from components.LevelSensor import LevelSensor
from components.TimeOfFlightLevelStrategy import TimeOfFlightLevelStrategy

global level_sensor

level_sensor = LevelSensor("test level sensor", TimeOfFlightLevelStrategy())
progress_tracker = ProgressTracker()

num = 7
levels = [level_sensor.get_level() for i in range(num)]

average_level = reduce(lambda x, y: (x + y), levels) / num
date_time = datetime.now().strftime("%H:%M")

progress_tracker.write_ln(f"{Style.WHITE}{Style.BOLD}{date_time}:{Style.RESET}{Style.GREEN} "
                          f"level: {Style.BOLD}{Style.WHITE}{'{:.2f}'.format(average_level)}")

Exemple #6
0
#!/usr/bin/env python3

import time

import RPi.GPIO as GPIO
import click

from Progress import ProgressBar, ProgressTracker
from components.Switch import Switch

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
channel = 27
GPIO.setup(channel, GPIO.OUT)

switch = Switch("pump out", channel, ProgressTracker())


@click.command()
@click.option('--time',
              '-t',
              'time_',
              default=0,
              help='how long to turn the pump on for')
def pump_out(time_: int):
    switch.on()

    progress_bar = ProgressBar()
    progress_bar.initialize()

    for i in range(time_):
#!/usr/bin/env python3

import time

import RPi.GPIO as GPIO
import click

from Progress import ProgressBar, ProgressTracker
from components.Switch import Switch

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
channel = 23
GPIO.setup(channel, GPIO.OUT)

switch = Switch("Pump in", channel, ProgressTracker())


@click.command()
@click.option('--time',
              '-t',
              'time_',
              default=0,
              help='How long to turn the pump on for')
def pump_in(time_: int):
    switch.on()

    progress_bar = ProgressBar()
    progress_bar.initialize()

    for i in range(time_):
Exemple #8
0
from Controller import Controller
from Progress import ProgressTracker, Style
from components.LevelSensor import LevelSensor
from components.LevelsBoundary import LevelsBoundary
from components.ReadingsSanitizer import ReadingsSanitizer
from components.Sump import Sump
from components.Switch import Switch
from components.TemperatureDetector import TemperatureDetector
from components.TemperatureSensor import TemperatureSensor
from components.TimeOfFlightLevelStrategy import TimeOfFlightLevelStrategy

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

logger = AquariumLogger()
progress_tracker = ProgressTracker()

current_dir = os.path.dirname(os.path.abspath(__file__))
configuration_file_name = "config.yaml"
configuration_file_path = f"{current_dir}/{configuration_file_name}"
config = Configuration(configuration_file_path)

full_level = config.get("full_level")
water_change_span = config.get("water_change_span")
empty_level = full_level + water_change_span

levels_boundary = LevelsBoundary(full_level, empty_level)
sanitizer = ReadingsSanitizer(levels_boundary,
                              config.get("accuracy_allowance"))

level_sensor = LevelSensor("level sensor", TimeOfFlightLevelStrategy())