class GPIOConfigTest(unittest.TestCase): def setUp(self): Singleton._instances = {} self.gpioConfig = GPIOConfig() def test_is_instance(self): self.assertTrue(isinstance(self.gpioConfig, GPIOConfig)) def test_generic_exec(self): GPIOConfig.status = MagicMock( side_effect=lambda value: value != GPIOPin.SWITCH_ROOF) GPIOConfig.wait_for_off = MagicMock(return_value=True) GPIOConfig.wait_for_on = MagicMock(return_value=True) self.gpioConfig.turn_on(GPIOPin.SWITCH_ROOF) self.gpioConfig.turn_off(GPIOPin.SWITCH_ROOF) self.assertTrue(self.gpioConfig.wait_for_on(GPIOPin.SWITCH_ROOF)) self.assertTrue(self.gpioConfig.wait_for_off(GPIOPin.SWITCH_ROOF)) self.assertFalse(self.gpioConfig.status(GPIOPin.SWITCH_ROOF)) def test_is_singleton(self): self.assertEqual(GPIOConfig(), self.gpioConfig) def test_timeout_value(self): cparser = configparser.ConfigParser() cparser.read('config.ini') self.assertEqual( config.Config.getInt("wait_for_timeout", "roof_board"), cparser["roof_board"].getint("wait_for_timeout")) self.assertEqual( config.Config.getInt("event_bouncetime", "roof_board"), cparser["roof_board"].getint("event_bouncetime"))
class RoofControl(metaclass=Singleton): def __init__(self): self.gpioconfig = GPIOConfig() def open(self): self.gpioconfig.turn_on(GPIOPin.SWITCH_ROOF) return self.gpioconfig.wait_for_off(GPIOPin.VERIFY_OPEN) def close(self): self.gpioconfig.turn_off(GPIOPin.SWITCH_ROOF) return self.gpioconfig.wait_for_off(GPIOPin.VERIFY_CLOSED) def read(self): is_roof_closed = self.gpioconfig.status(GPIOPin.VERIFY_CLOSED) is_roof_open = self.gpioconfig.status(GPIOPin.VERIFY_OPEN) is_switched_on = self.gpioconfig.status(GPIOPin.SWITCH_ROOF) if is_roof_closed and is_roof_open: return Status.ERROR elif is_roof_closed and not is_switched_on: return Status.CLOSED elif is_roof_open and is_switched_on: return Status.OPEN elif is_switched_on: return Status.OPENING else: return Status.CLOSING
class ButtonControl(): def __init__(self, pin): self.pin = pin self.gpioconfig = GPIOConfig() def on(self): self.gpioconfig.turn_on(self.pin) def off(self): self.gpioconfig.turn_off(self.pin) def read(self): if self.gpioconfig.status(self.pin): return ButtonStatus.ON else: return ButtonStatus.OFF
power_ccd = data[4] curtain_west = data[5] curtain_east = data[6] else: try: conn.close() finally: break # ROOF if roof == 'O': Logger.getLogger().debug("test apertura tetto") gpioConfig.turn_on(GPIOPin.SWITCH_ROOF) Logger.getLogger().debug("MOTORE TETTO: %s", gpioConfig.status(GPIOPin.SWITCH_ROOF)) if roof == 'C': Logger.getLogger().debug("test chiusura tetto") gpioConfig.turn_off(GPIOPin.SWITCH_ROOF) Logger.getLogger().debug("MOTORE TETTO: %s", gpioConfig.status(GPIOPin.SWITCH_ROOF)) # PANEL FLAT if panel == 'A': Logger.getLogger().debug("test accensione pannello flat") gpioConfig.turn_on(GPIOPin.SWITCH_PANEL) Logger.getLogger().debug("PANEL FLAT: %s", gpioConfig.status(GPIOPin.SWITCH_PANEL)) if panel == 'S': Logger.getLogger().debug("test spegnimento panel flat") gpioConfig.turn_off(GPIOPin.SWITCH_PANEL) Logger.getLogger().debug("PANEL FLAT: %s", gpioConfig.status(GPIOPin.SWITCH_PANEL)) # POWER SWITCH TELE if power_tele == 'A': Logger.getLogger().debug("test accensione alimentatore telescopio")