def test_away_mode(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2, away_delta=10, ) self.interface.automatic = None self.device.command((Command.SETPOINT, 72)) self.device.command(Command.AUTOMATIC) self.device.command(Command.VACATE) # time.sleep(2) self.interface.vacate.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') assert not self.interface.cool.called self.device.command(command=(Command.SETPOINT, 83), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 67), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(command=(Command.SETPOINT, 61), source=self.interface, address='a') self.interface.heat.assert_called_with('a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.device.command(command=(Command.SETPOINT, 68), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(Command.OCCUPY) self.device.command(command=(Command.SETPOINT, 68), source=self.interface, address='a') self.interface.occupy.assert_called_with('a') self.interface.heat.assert_called_with('a')
def test_automatic_delta_setpoint_switchover(self): self.device = Thermostat(address='a', devices=self.interface, automatic_delta=2) self.interface.automatic = None self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') self.device.command((Command.SETPOINT, 70)) # we are not in automatic mode yet assert not self.interface.cool.called self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 71), source=self.interface, address='a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() # reset set point within delta self.device.command((Command.SETPOINT, 72)) assert not self.interface.heat.called self.device.command(command=(Command.SETPOINT, 69), source=self.interface, address='a') self.interface.heat.assert_called_with('a')
def test_away_mode(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2, away_delta=10, ) self.interface.automatic = None self.device.command((Command.LEVEL, 72)) self.device.command(Command.AUTOMATIC) self.device.command(Command.VACATE) # time.sleep(2) self.interface.vacate.assert_called_with('a') self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') assert not self.interface.cool.called self.device.command(command=(Command.LEVEL, 83), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.LEVEL, 67), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(command=(Command.LEVEL, 61), source=self.interface, address='a') self.interface.heat.assert_called_with('a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.device.command(command=(Command.LEVEL, 68), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(Command.OCCUPY) self.device.command(command=(Command.LEVEL, 68), source=self.interface, address='a') self.interface.occupy.assert_called_with('a') self.interface.heat.assert_called_with('a')
def test_automatic_delta(self): self.device = Thermostat( address='192.168.1.3', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command((Command.SETPOINT, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) self.interface.level.reset_mock() self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called
def test_automatic_delta(self): self.device = Thermostat( address='192.168.1.3', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command((Command.LEVEL, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) self.interface.level.reset_mock() self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called
def test_automatic_delta_setpoint_switchover(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') self.device.command((Command.LEVEL, 70)) # we are not in automatic mode yet assert not self.interface.cool.called self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.LEVEL, 71), source=self.interface, address='a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() # reset set point within delta self.device.command((Command.LEVEL, 72)) assert not self.interface.heat.called self.device.command(command=(Command.LEVEL, 69), source=self.interface, address='a') self.interface.heat.assert_called_with('a')
insteon = InsteonHub( HTTP(host='IPAddressOrNamedDHCPEntry', username='******', password='******', port='25105')) ozw = Open_zwave(serialDevicePath="/dev/zwave", config_path="/etc/openzwave") #Thermostat (override available commads) thermostat_commands = [ Command.AUTOMATIC, Command.COOL, Command.HEAT, Command.HOLD, Command.SCHEDULE, Command.OFF, Command.LEVEL, Command.CIRCULATE, Command.STILL, Command.VACATE, Command.OCCUPY, Command.SETPOINT ] hall_thermostat = Thermostat(commands=thermostat_commands, name="Thermostat", devices=VenstarThermostat( HTTP(host='HallThermostat'), type='commercial')) #Sensors ph_calculated = Location('38.576492', '-121.493375', tz='America/Los_Angeles', mode=Location.MODE.STANDARD, is_dst=True, name='Calculated Photocell') #Front Door sensor, remove non functional status command d_front_door = Door(address='2AF9B7', devices=(insteon), name="Front Door Sensor",
def test_thermostat_setpoint(self): d = Thermostat(address=(123, 123), devices=self.interface, name='Thermo1') d.level(74)
def test_thermostat_setpoint(self): d = Thermostat(address=(123,123), devices=self.interface, name='Thermo1') d.level(74)
def setUp(self): self.interface = Mock() self.device = Thermostat('192.168.1.3', self.interface)
class ThermostatTests(TestCase): def setUp(self): self.interface = Mock() self.device = Thermostat('192.168.1.3', self.interface) def test_instantiation(self): self.assertIsNotNone(self.device) def test_cool(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.cool() self.assertEqual(self.device.state, State.COOL) self.interface.cool.assert_called_with('192.168.1.3') def test_heat(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.heat() self.assertEqual(self.device.state, State.HEAT) self.interface.heat.assert_called_with('192.168.1.3') def test_off(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.off() self.assertEqual(self.device.state, State.OFF) self.interface.off.assert_called_with('192.168.1.3') def test_level(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.level(72) self.assertEqual(self.device.state, (State.LEVEL, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) def test_circulate(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.circulate() self.assertEqual(self.device.state, State.CIRCULATE) self.interface.circulate.assert_called_with('192.168.1.3') def test_automatic_mode_for_device_that_does_not(self): #Oddly enough the homewerks thermostat doesnt have an auto mode self.interface.automatic = None self.device.command((Command.LEVEL, 72)) self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') self.interface.level.assert_called_with('192.168.1.3', 72) assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 54), source=self.interface, address='192.168.1.3') self.interface.heat.assert_called_with('192.168.1.3') assert not self.interface.level.called # Test that it does not repeat mode setting unnecessarily self.interface.heat.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 58), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 98), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called # Test the delta setting self.device.automatic_delta(1) self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called self.device.command(command=(Command.LEVEL, 70), source=self.interface, address='192.168.1.3') self.interface.heat.assert_called_with('192.168.1.3') def test_automatic_delta(self): self.device = Thermostat( address='192.168.1.3', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command((Command.LEVEL, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) self.interface.level.reset_mock() self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.LEVEL, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called def test_automatic_delta_setpoint_switchover(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') self.device.command((Command.LEVEL, 70)) # we are not in automatic mode yet assert not self.interface.cool.called self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.LEVEL, 71), source=self.interface, address='a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() # reset set point within delta self.device.command((Command.LEVEL, 72)) assert not self.interface.heat.called self.device.command(command=(Command.LEVEL, 69), source=self.interface, address='a') self.interface.heat.assert_called_with('a') def test_hold(self): assert not self.interface.hold.called self.device.command(Command.HOLD) self.interface.hold.assert_called_with('192.168.1.3') def test_away_mode(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2, away_delta=10, ) self.interface.automatic = None self.device.command((Command.LEVEL, 72)) self.device.command(Command.AUTOMATIC) self.device.command(Command.VACATE) # time.sleep(2) self.interface.vacate.assert_called_with('a') self.device.command(command=(Command.LEVEL, 76), source=self.interface, address='a') assert not self.interface.cool.called self.device.command(command=(Command.LEVEL, 83), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.LEVEL, 67), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(command=(Command.LEVEL, 61), source=self.interface, address='a') self.interface.heat.assert_called_with('a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.device.command(command=(Command.LEVEL, 68), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(Command.OCCUPY) self.device.command(command=(Command.LEVEL, 68), source=self.interface, address='a') self.interface.occupy.assert_called_with('a') self.interface.heat.assert_called_with('a')
class ThermostatTests(TestCase): def setUp(self): self.interface = Mock() self.device = Thermostat('192.168.1.3', self.interface) def test_instantiation(self): self.assertIsNotNone(self.device) def test_cool(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.cool() self.assertEqual(self.device.state, State.COOL) self.interface.cool.assert_called_with('192.168.1.3') def test_heat(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.heat() self.assertEqual(self.device.state, State.HEAT) self.interface.heat.assert_called_with('192.168.1.3') def test_off(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.off() self.assertEqual(self.device.state, State.OFF) self.interface.off.assert_called_with('192.168.1.3') def test_level(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.level(72) self.assertEqual(self.device.state, (State.LEVEL, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) def test_circulate(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.circulate() self.assertEqual(self.device.state, State.CIRCULATE) self.interface.circulate.assert_called_with('192.168.1.3') def test_automatic_mode_for_device_that_does_not(self): #Oddly enough the homewerks thermostat doesnt have an auto mode self.interface.automatic = None self.device.command((Command.SETPOINT, 72)) self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') self.interface.level.assert_called_with('192.168.1.3', 72) assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 54), source=self.interface, address='192.168.1.3') self.interface.heat.assert_called_with('192.168.1.3') assert not self.interface.level.called # Test that it does not repeat mode setting unnecessarily self.interface.heat.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 58), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 98), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called # Test the delta setting self.device.automatic_delta(1) self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called assert not self.interface.level.called self.device.command(command=(Command.SETPOINT, 70), source=self.interface, address='192.168.1.3') self.interface.heat.assert_called_with('192.168.1.3') def test_automatic_delta(self): self.device = Thermostat( address='192.168.1.3', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command((Command.SETPOINT, 72)) self.interface.level.assert_called_with('192.168.1.3', 72) self.interface.level.reset_mock() self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='192.168.1.3') self.interface.cool.assert_called_with('192.168.1.3') assert not self.interface.heat.called self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() self.device.command(command=(Command.SETPOINT, 71), source=self.interface, address='192.168.1.3') assert not self.interface.heat.called def test_automatic_delta_setpoint_switchover(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2 ) self.interface.automatic = None self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') self.device.command((Command.SETPOINT, 70)) # we are not in automatic mode yet assert not self.interface.cool.called self.device.command(Command.AUTOMATIC) self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 71), source=self.interface, address='a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.interface.level.reset_mock() # reset set point within delta self.device.command((Command.SETPOINT, 72)) assert not self.interface.heat.called self.device.command(command=(Command.SETPOINT, 69), source=self.interface, address='a') self.interface.heat.assert_called_with('a') def test_hold(self): assert not self.interface.hold.called self.device.command(Command.HOLD) self.interface.hold.assert_called_with('192.168.1.3') def test_away_mode(self): self.device = Thermostat( address='a', devices=self.interface, automatic_delta=2, away_delta=10, ) self.interface.automatic = None self.device.command((Command.SETPOINT, 72)) self.device.command(Command.AUTOMATIC) self.device.command(Command.VACATE) # time.sleep(2) self.interface.vacate.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 76), source=self.interface, address='a') assert not self.interface.cool.called self.device.command(command=(Command.SETPOINT, 83), source=self.interface, address='a') self.interface.cool.assert_called_with('a') self.device.command(command=(Command.SETPOINT, 67), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(command=(Command.SETPOINT, 61), source=self.interface, address='a') self.interface.heat.assert_called_with('a') self.interface.heat.reset_mock() self.interface.cool.reset_mock() self.device.command(command=(Command.SETPOINT, 68), source=self.interface, address='a') assert not self.interface.heat.called self.device.command(Command.OCCUPY) self.device.command(command=(Command.SETPOINT, 68), source=self.interface, address='a') self.interface.occupy.assert_called_with('a') self.interface.heat.assert_called_with('a')
sg.dio_invert(5) sg.dio_invert(6) sg.dio_invert(7) sg.dio_invert(8) sg.dio_invert(9) sg.dio_invert(10) sg.dio_invert(11) sg.dio_invert(12) # My camera motion software will echo a "motion" to this pipe. pipe_front_yard_motion = StateInterface(NamedPipe('/tmp/front_yard_motion')) thermostat_upstairs = Thermostat( devices=HW_Thermostat(HTTP(host='192.168.13.211'), poll=60), name='Thermostat Upstairs', automatic_delta=2, time=({ Attribute.TIME: (0, 30, 5, '*', '*', (1, 2, 3, 4, 5)), Attribute.COMMAND: (Command.LEVEL, 72), }, )) thermostat_downstairs = Thermostat(devices=HW_Thermostat( HTTP(host='192.168.13.210'), poll=60), name='Thermostat Downstairs', automatic_delta=2) ###################### DEVICE CONFIG ######################### #doors d_foyer = Door('D1', sg, name='Foyer Door') d_laundry = Door('D2', sg, name='Laundry Door') d_garage = Door('D3', sg, name='Garage Door')