Ejemplo n.º 1
0
    def testOnAction_masterIsOn_returnsTrueAndNotTurningOffOpenSpaceNeighbor(
            self):
        self.illuminanceSensorItem.setState(
            DecimalType(ILLUMINANCE_THRESHOLD_IN_LUX - 1))

        # zone3 (foyer) is an open space neighbor with zone2
        self.zone2 = self.zone2.addNeighbor(
            Neighbor(self.zone3.getId(), NeighborType.OPEN_SPACE))
        # zone2 (kitchen) is an open space slave with zone1 (great room)
        self.zone2 = self.zone2.addNeighbor(
            Neighbor(self.zone1.getId(), NeighborType.OPEN_SPACE_MASTER))

        # Turn on the light in the great room and the foyer.
        # We want to make sure that when the motion sensor in the kitchen is
        # triggered, it won't be turn on, and also the foyer light must not
        # be turned off.
        # The rationale is that someone just open the door to come to the foyer
        # area. However, as the great room light was already on, that indicates
        # someone is already in that area. As such, any movement in that
        # area must not prematurely turn off the the foyer light.
        self.lightItem1.setState(scope.OnOffType.ON)
        self.lightItem3.setState(scope.OnOffType.ON)

        eventInfo = EventInfo(ZoneEvent.MOTION, ITEMS[0], self.zone2,
                              self.createMockedZoneManager(),
                              self.getMockedEventDispatcher())
        returnVal = TurnOnSwitch().onAction(eventInfo)
        self.assertFalse(returnVal)
        self.assertFalse(self.zone2.isLightOn())
        self.assertTrue(self.zone3.isLightOn())
Ejemplo n.º 2
0
    def testOnMotionSensorTurnedOn_notLightOnTime_returnsFalse(self):
        self.astroSensorItem.setState(StringType('MORNING'))

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

        isProcessed = zone.dispatchEvent(ZoneEvent.MOTION,
                                         self.getMockedEventDispatcher(),
                                         self.motionSensor.getItem(), None,
                                         True)
        self.assertFalse(isProcessed)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def testOnMotionSensorTurnedOn_withApplicableZone_returnsTrue(self):
        self.assertFalse(self.light.isOn())
        self.illuminanceSensorItem.setState(
            DecimalType(ILLUMINANCE_THRESHOLD_IN_LUX - 1))

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

        self.assertTrue(
            self.zm.dispatchEvent(ZoneEvent.MOTION, scope.events,
                                  self.motionSensor.getItem()))
Ejemplo n.º 5
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())
Ejemplo n.º 6
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())
Ejemplo n.º 7
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())
Ejemplo n.º 8
0
 def testAddAction_twoValidAction_actionAdded(self):
     zone = Zone('ff').addAction(TurnOnSwitch())
     zone = zone.addAction(TurnOffAdjacentZones())
     self.assertEqual(1, len(zone.getActions(ZoneEvent.MOTION)))
     self.assertEqual(1, len(zone.getActions(ZoneEvent.SWITCH_TURNED_ON)))
Ejemplo n.º 9
0
 def turnOn(self):
     eventInfo = EventInfo(ZoneEvent.MOTION, ITEMS[0], self.zone1,
                           self.createMockedZoneManager(),
                           self.getMockedEventDispatcher())
     return TurnOnSwitch().onAction(eventInfo)
def initializeZoneManager():
    '''
    Creates a new instance of ZoneManager and populate the zones.

    :rtype: ZoneManager
    '''
    zm = ZoneManager()
    zones = ZoneParser().parse(items, itemRegistry, zm._createImmutableInstance())

    # actions
    externalZoneActions = [
        AlertOnEntraceActivity(),
        SimulateDaytimePresence("http://hestia2.cdnstream.com:80/1277_192"),
        AlertOnExternalDoorLeftOpen(),
        ArmAfterFrontDoorClosed(12 * 60), # arm after 12'
    ]

    fanActions = [PlayMusicDuringShower("http://hestia2.cdnstream.com:80/1277_192")]

    switchActions = [TurnOnSwitch(), TurnOffAdjacentZones()]

    # add virtual devices and actions
    for z in zones:
        if z.getName() == 'Virtual':
            timeMap = {
                'wakeup': '6 - 9',
                'lunch': '12:00 - 13:30',
                'quiet' : '14:00 - 16:00, 20:00 - 22:59',
                'dinner': '17:50 - 20:00',
                'sleep': '23:00 - 7:00' 
            }
            z = z.addDevice(ActivityTimes(timeMap))

        if len(z.getDevicesByType(Switch)) > 0:
            for a in switchActions:
                z = z.addAction(a)

        if z.isExternal():
            for a in externalZoneActions:
                z = z.addAction(a)

        if len(z.getDevicesByType(AlarmPartition)) > 0:
            z = z.addAction(TurnOffDevicesOnAlarmModeChange())

        if len(z.getDevicesByType(HumiditySensor)) > 0 and not z.isExternal():
            z = z.addAction(AlertOnHumidityOutOfRange())

        if len(z.getDevicesByType(GasSensor)) > 0:
            z = z.addAction(AlertOnHighGasLevel())

        # add the play music action if zone has a fan switch.
        fans = z.getDevicesByType(Fan)
        if len(fans) > 0:
            for a in fanActions:
                z = z.addAction(a)

        zm.addZone(z)

    PE.logInfo("Configured ZoneManager with {} zones.".format(len(zones)))

    zones = zm.getZones()
    output = "{} zones".format(len(zones))
    for z in zones:
        output += '\n' + str(z)
    PE.logInfo(output)

    zm.startAutoReporWatchDog()

    return zm