# Path: controller/util.py
# def mapping(x, in_min, in_max, out_min, out_max):
#     return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
# 
# def constrain(x, out_min, out_max):
#     return min(max(x, out_min), out_max)


import time
import logging
import re
import serial
import io
import subprocess
from abc import abstractmethod, ABC
from .util import mapping, constrain
        from lcdbackpack import LcdBackpack

class DeviceRegistry(object):

    def __init__(self):
        self.__valves = {}
        self.__pumps = {}
        self.__sensors = {}
        self.__devices = {}

    def get_valves(self):
        return self.__valves.values()

    def get_pumps(self):
        return self.__pumps.values()

    def get_sensors(self):
        return self.__sensors.values()

    def get_devices(self):
        return self.__devices.values()

    def add_valve(self, device):
        assert isinstance(device, SwitchDevice)
        self.__valves[device.name] = device

    def add_pump(self, device):
        assert isinstance(device, (SwitchDevice, PumpDevice))
        self.__pumps[device.name] = device

    def add_sensor(self, device):

# Path: controller/util.py
# def mapping(x, in_min, in_max, out_min, out_max):
#     return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
# 
# def constrain(x, out_min, out_max):
#     return min(max(x, out_min), out_max)


# Path: controller/device.py
import time
import logging
import re
import serial
import io
import subprocess
from abc import abstractmethod, ABC
from .util import mapping, constrain
        from lcdbackpack import LcdBackpack


class DeviceRegistry(object):

    def __init__(self):
        self.__valves = {}
        self.__pumps = {}
        self.__sensors = {}
        self.__devices = {}

    def get_valves(self):
        return self.__valves.values()

    def get_pumps(self):
        return self.__pumps.values()

    def get_sensors(self):
        return self.__sensors.values()

    def get_devices(self):
        return self.__devices.values()

    def add_valve(self, device):
        assert isinstance(device, SwitchDevice)
        self.__valves[device.name] = device

    def add_pump(self, device):
        assert isinstance(device, (SwitchDevice, PumpDevice))
        self.__pumps[device.name] = device

    def add_sensor(self, device):

        assert isinstance(device, SensorDevice)