Esempio n. 1
0
    def testGetDeviceByEvent_invalidEvent_returnsNone(self):
        zone = Zone('ff', [self.light])

        eventInfo = EventInfo(ZoneEvent.MOTION, self.motionSensorItem, zone,
                              MockedZoneManager([zone]),
                              self.getMockedEventDispatcher())
        self.assertEqual(None, zone.getDeviceByEvent(eventInfo))
    def setUp(self):
        super(TurnOffAdjacentZonesTest, self).setUp()

        [self.lightItem1, self.lightItem2, self.lightItem3,
         self.fanItem] = self.getItems()

        self.light1 = Light(self.lightItem1, 5)
        self.light2 = Light(self.lightItem2, 5)
        self.light3 = Light(self.lightItem3, 5, ILLUMINANCE_THRESHOLD_IN_LUX,
                            False, "0-23:59")  # always stay on
        self.fan = Fan(self.fanItem, 5)

        self.washroom = Zone('washroom', [self.light1])
        self.shower = Zone('shower', [self.fan])
        self.lobby = Zone('lobby', [self.light2])
        self.foyer = Zone('foyer', [self.light3])
        self.zoneManager = MockedZoneManager(
            [self.washroom, self.shower, self.lobby, self.foyer])

        self.lobby = self.lobby.addNeighbor(
            Neighbor(self.foyer.getId(), NeighborType.OPEN_SPACE))

        self.washroom = self.washroom.addNeighbor(
            Neighbor(self.lobby.getId(), NeighborType.OPEN_SPACE))
        self.washroom = self.washroom.addNeighbor(
            Neighbor(self.shower.getId(), NeighborType.OPEN_SPACE))
Esempio n. 3
0
    def testGetDeviceByEvent_validEvent_returnsExpectedDevice(self):
        zone = Zone('ff', [self.light])

        eventInfo = EventInfo(ZoneEvent.MOTION, self.lightItem, zone,
                              MockedZoneManager([zone]),
                              self.getMockedEventDispatcher())
        self.assertEqual(self.light, zone.getDeviceByEvent(eventInfo))
Esempio n. 4
0
    def createTestData(self, excludedDevices=[], extraIncludedDevices=[]):
        '''
        :return: a list of two zones, the mocked zone manager, and the event dispatcher
        :rtype: list
        '''

        self.partition.armAway(self.getMockedEventDispatcher())

        porch = Zone.createExternalZone('porch').addDevice(self.partition)
        greatRoom = Zone("GR", [self.audioSink], Level.FIRST_FLOOR)

        for d in excludedDevices:
            if porch.hasDevice(d):
                porch = porch.removeDevice(d)

            if greatRoom.hasDevice(d):
                greatRoom = greatRoom.removeDevice(d)

        for d in extraIncludedDevices:
            greatRoom = greatRoom.addDevice(d)

        zm = MockedZoneManager([porch, greatRoom])

        eventInfo = EventInfo(ZoneEvent.MOTION, ITEMS[0], porch, zm,
                              self.getMockedEventDispatcher())

        return [porch, greatRoom, zm, eventInfo]
Esempio n. 5
0
    def testGetNeighborZones_noNeighborTypesSpecified_returnsCorrectList(self):
        zone1 = Zone('foyer')
        zone2 = Zone('porch')
        zone3 = Zone('office')

        zone1 = zone1.addNeighbor(
            Neighbor(zone2.getId(), NeighborType.OPEN_SPACE))
        zone1 = zone1.addNeighbor(
            Neighbor(zone3.getId(), NeighborType.OPEN_SPACE_MASTER))
        zm = MockedZoneManager([zone1, zone2, zone3])

        self.assertEqual(2, len(zone1.getNeighborZones(zm)))
Esempio n. 6
0
    def testOnMotionSensorTurnedOn_validItemNameNoIlluminanceSensorNoAstroSensor_returnsFalse(
            self):
        self.assertFalse(self.light.isOn())

        zone = Zone('ff', [self.light, self.motionSensor])
        zone = zone.addAction(TurnOnSwitch())

        isProcessed = zone.dispatchEvent(ZoneEvent.MOTION,
                                         self.getMockedEventDispatcher(),
                                         self.motionSensor.getItem(),
                                         MockedZoneManager([zone]), True)
        self.assertFalse(isProcessed)
Esempio n. 7
0
    def testOnAction_switchOnEventAndAudioSinkInNeighborZone_playsStreamAndReturnsTrue(
            self):
        zone1 = Zone('shower')
        zone2 = Zone('washroom').addDevice(self.sink)

        zone1 = zone1.addNeighbor(
            Neighbor(zone2.getId(), NeighborType.OPEN_SPACE))

        eventInfo = EventInfo(ZoneEvent.SWITCH_TURNED_ON, ITEMS[0], zone1,
                              MockedZoneManager([zone1, zone2]), scope.events)
        value = self.action.onAction(eventInfo)
        self.assertTrue(value)
        self.assertEqual('playStream', self.sink._getLastTestCommand())
Esempio n. 8
0
    def testOnMotionSensorTurnedOn_lightOnTime_turnsOnLight(self):
        self.assertFalse(self.light.isOn())

        self.astroSensorItem.setState(StringType(
            AstroSensor.LIGHT_ON_TIMES[0]))
        zone = Zone('ff', [self.light, self.motionSensor, self.astroSensor])
        zone = zone.addAction(TurnOnSwitch())

        isProcessed = zone.dispatchEvent(ZoneEvent.MOTION,
                                         self.getMockedEventDispatcher(),
                                         self.motionSensor.getItem(),
                                         MockedZoneManager([zone]), True)
        self.assertTrue(isProcessed)
        self.assertTrue(self.light.isOn())
Esempio n. 9
0
    def createTestData(self, zoneEvent):
        '''
        :return: a list of two zones, the mocked zone manager, and the event dispatcher
        :rtype: list
        '''

        self.partition.armAway(self.getMockedEventDispatcher())

        zone = Zone('porch', [self.partition, self.light, self.audioSink])
        zm = MockedZoneManager([zone])
        eventInfo = EventInfo(zoneEvent, ITEMS[0], zone, zm,
                              self.getMockedEventDispatcher())

        return [zone, zm, eventInfo]
Esempio n. 10
0
    def testOnMotionSensorTurnedOn_illuminanceAboveThreshold_returnsFalse(
            self):
        self.assertFalse(self.light.isOn())
        self.illuminanceSensorItem.setState(
            DecimalType(ILLUMINANCE_THRESHOLD_IN_LUX + 1))

        zone = Zone('ff', [
            self.lightWithIlluminance, self.motionSensor,
            self.illuminanceSensor
        ])
        zone = zone.addAction(TurnOnSwitch())

        isProcessed = zone.dispatchEvent(ZoneEvent.MOTION,
                                         self.getMockedEventDispatcher(),
                                         self.motionSensor.getItem(),
                                         MockedZoneManager([zone]), True)
        self.assertFalse(isProcessed)
        self.assertFalse(self.light.isOn())
Esempio n. 11
0
    def testOnMotionSensorTurnedOn_notLightOnTimeButIlluminanceBelowThreshold_turnsOnLight(
            self):
        self.assertFalse(self.light.isOn())
        self.illuminanceSensorItem.setState(
            DecimalType(ILLUMINANCE_THRESHOLD_IN_LUX - 1))
        self.astroSensorItem.setState(StringType('MORNING'))

        zone = Zone('ff', [
            self.lightWithIlluminance, self.motionSensor,
            self.illuminanceSensor, self.astroSensor
        ])
        zone = zone.addAction(TurnOnSwitch())

        isProcessed = zone.dispatchEvent(ZoneEvent.MOTION,
                                         self.getMockedEventDispatcher(),
                                         self.motionSensor.getItem(),
                                         MockedZoneManager([zone]), True)
        self.assertTrue(isProcessed)
        self.assertTrue(self.light.isOn())
Esempio n. 12
0
 def createMockedZoneManager(self):
     return MockedZoneManager([self.zone1, self.zone2, self.zone3])
Esempio n. 13
0
 def testOnAction_noAudioSink_returnsFalse(self):
     eventInfo = EventInfo(ZoneEvent.SWITCH_TURNED_ON, ITEMS[0],
                           Zone('innerZone'), MockedZoneManager([]),
                           scope.events)
     value = self.action.onAction(eventInfo)
     self.assertFalse(value)