コード例 #1
0
    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))
コード例 #2
0
ファイル: zone_test.py プロジェクト: yfaway/openhab-rules
    def setUp(self):
        super(ZoneTest, self).setUp()

        [
            self.lightItem, self.motionSensorItem, self.illuminanceSensorItem,
            self.astroSensorItem, self.dimmerItem, self.fanItem, self.plugItem,
            self.plugPowerItem
        ] = self.getItems()

        self.illuminanceSensor = IlluminanceSensor(self.illuminanceSensorItem)
        self.light = Light(self.lightItem, 2)
        self.lightWithIlluminance = Light(self.lightItem, 2,
                                          ILLUMINANCE_THRESHOLD_IN_LUX)
        self.motionSensor = MotionSensor(self.motionSensorItem)
        self.astroSensor = AstroSensor(self.astroSensorItem)
        self.dimmer = Dimmer(self.dimmerItem, 2, 100, "0-23:59")
        self.fan = Fan(self.lightItem, 2)
コード例 #3
0
    def testOnAction_switchDisablesTriggeringByMotionSensor_returnsFalse(self):
        self.light1 = Light(self.lightItem1, 30, ILLUMINANCE_THRESHOLD_IN_LUX,
                            True)
        self.zone1 = Zone('foyer', [self.light1, self.illuminanceSensor])

        self.illuminanceSensorItem.setState(
            DecimalType(ILLUMINANCE_THRESHOLD_IN_LUX - 1))

        self.assertFalse(self.turnOn())
コード例 #4
0
    def setUp(self):
        scope.itemRegistry.remove(LIGHT_SWITCH_NAME)
        scope.itemRegistry.remove(TIMER_NAME)

        self.lightItem = SwitchItem(LIGHT_SWITCH_NAME)
        scope.itemRegistry.add(self.lightItem)

        self.lightItem.setState(scope.OnOffType.OFF)

        self.light = Light(self.lightItem, 10)
コード例 #5
0
    def setUp(self):
        super(TurnOnSwitchTest, self).setUp()

        [
            self.lightItem1, self.lightItem2, self.illuminanceSensorItem,
            self.motionSensorItem1, self.motionSensorItem2, self.lightItem3
        ] = self.getItems()

        self.illuminanceSensor = IlluminanceSensor(self.illuminanceSensorItem)
        self.light1 = Light(self.lightItem1, 30, ILLUMINANCE_THRESHOLD_IN_LUX)
        self.light2 = Light(self.lightItem2, 30, ILLUMINANCE_THRESHOLD_IN_LUX)
        self.light3 = Light(self.lightItem3, 30, ILLUMINANCE_THRESHOLD_IN_LUX)
        self.motionSensor1 = MotionSensor(self.motionSensorItem1)
        self.motionSensor2 = MotionSensor(self.motionSensorItem2)

        self.zone1 = Zone(
            'great room',
            [self.light1, self.illuminanceSensor, self.motionSensor1])
        self.zone2 = Zone(
            'kitchen',
            [self.light2, self.illuminanceSensor, self.motionSensor2])
        self.zone3 = Zone('foyer', [self.light3, self.illuminanceSensor])
コード例 #6
0
    def setUp(self):
        super(TurnOffDevicesOnAlarmModeChangeTest, self).setUp()

        self.audioSink = ChromeCastAudioSink('prefix', 'sinkName')
        self.partition = AlarmPartition(ITEMS[1], ITEMS[2])
        self.light = Light(ITEMS[3], ITEMS[4])

        self.action = TurnOffDevicesOnAlarmModeChange()

        self.audioSink._setTestMode()

        self.audioSink.playStream("http://stream")
        self.light.turnOn(self.getMockedEventDispatcher())
        self.partition.disarm(self.getMockedEventDispatcher())
コード例 #7
0
    def testTimerTurnedOff_validParams_switchIsOff(self):
        zm = ZoneManager()
        self.light = Light(self.lightItem, 0.004)  # makes it 0.24 sec
        self.light = self.light.setZoneManager(zm._createImmutableInstance())

        zone = Zone('ff', [self.light])
        zm.addZone(zone)

        self.lightItem.setState(scope.OnOffType.ON)
        self.light._startTimer(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.light._isTimerActive())

        time.sleep(0.3)
        self.assertFalse(self.light._isTimerActive())
        self.assertFalse(self.light.isOn())
コード例 #8
0
 def testIsLowIlluminance_currentIlluminanceBelowThreshold_returnsTrue(
         self):
     self.light = Light(self.lightItem, 10, 50)
     self.assertTrue(self.light.isLowIlluminance(10))
コード例 #9
0
 def testIsLowIlluminance_currentIlluminanceAboveThreshold_returnsFalse(
         self):
     self.light = Light(self.lightItem, 10, 50)
     self.assertFalse(self.light.isLowIlluminance(60))
コード例 #10
0
 def testIsLowIlluminance_currentIlluminanceNotAvailable_returnsFalse(self):
     self.light = Light(self.lightItem, 10, 50)
     self.assertFalse(self.light.isLowIlluminance(-1))
コード例 #11
0
    def _createSwitches(self, deviceName, openHabItem, zone, itemRegistry,
                        neighbors):
        itemName = openHabItem.getName()
        zoneId = zone.getId()

        if 'LightSwitch' == deviceName:
            # open space relationship
            turnOffMeta = MetadataRegistry.get(
                MetadataKey(META_TURN_OFF_OTHER_LIGHT, itemName))
            if None != turnOffMeta:
                neighborZoneId = self._getZoneIdFromItemName(turnOffMeta.value)

                neighbor = [zoneId, neighborZoneId, NeighborType.OPEN_SPACE]
                neighbors.append(neighbor)

            # master-slave open space relationship
            masterSlaveMeta = MetadataRegistry.get(
                MetadataKey(
                    META_DISABLE_MOTION_TRIGGERING_IF_OTHER_LIGHT_IS_ON,
                    itemName))
            if None != masterSlaveMeta:
                masterZoneId = self._getZoneIdFromItemName(
                    masterSlaveMeta.value)

                neighborForward = [
                    masterZoneId, zoneId, NeighborType.OPEN_SPACE_SLAVE
                ]
                neighbors.append(neighborForward)

                neighborReverse = [
                    zoneId, masterZoneId, NeighborType.OPEN_SPACE_MASTER
                ]
                neighbors.append(neighborReverse)

            # noPrematureTurnOffTimeRange
            noPrematureTurnOffTimeRange = None
            noPrematureTurnOffTimeRangeMeta = MetadataRegistry.get(
                MetadataKey(META_NO_PREMATURE_TURN_OFF_TIME_RANGE, itemName))
            if None != noPrematureTurnOffTimeRangeMeta:
                noPrematureTurnOffTimeRange = noPrematureTurnOffTimeRangeMeta.value

            disableMotionSensorTriggering = openHabItem.hasTag(
                TAG_DISABLE_TRIGGERING_FROM_MOTION_SENSOR)

            durationMeta = MetadataRegistry.get(
                MetadataKey('durationInMinutes', itemName))
            if None != durationMeta:
                durationInMinutes = int(durationMeta.value)
            else:
                raise ValueError(
                    'Missing durationInMinutes value for {}'.format(itemName))

            # dimmer setting
            meta = MetadataRegistry.get(
                MetadataKey(META_DIMMING_SETTING, itemName))
            if None != meta:
                config = meta.configuration
                level = config['level'].intValue()
                timeRanges = config['timeRanges']

                switch = Dimmer(openHabItem, durationInMinutes, level,
                                timeRanges, ILLUMINANCE_THRESHOLD_IN_LUX,
                                disableMotionSensorTriggering,
                                noPrematureTurnOffTimeRange)
            else:
                switch = Light(openHabItem, durationInMinutes,
                               ILLUMINANCE_THRESHOLD_IN_LUX,
                               disableMotionSensorTriggering,
                               noPrematureTurnOffTimeRange)

            return switch
        elif 'FanSwitch' == deviceName:
            durationMeta = MetadataRegistry.get(
                MetadataKey('durationInMinutes', itemName))
            if None != durationMeta:
                durationInMinutes = int(durationMeta.value)
            else:
                raise ValueError(
                    'Missing durationInMinutes value for {}'.format(itemName))

            return Fan(openHabItem, durationInMinutes)
        elif 'Wled_MasterControls' in deviceName:
            effectItem = itemRegistry.getItem(
                itemName.replace('MasterControls', 'FX'))
            primaryColorItem = itemRegistry.getItem(
                itemName.replace('MasterControls', 'Primary'))
            secondaryColorItem = itemRegistry.getItem(
                itemName.replace('MasterControls', 'Secondary'))

            durationMeta = MetadataRegistry.get(
                MetadataKey('durationInMinutes', itemName))
            if None != durationMeta:
                durationInMinutes = int(durationMeta.value)
            else:
                raise ValueError(
                    'Missing durationInMinutes value for {}'.format(itemName))

            return Wled(openHabItem, effectItem, primaryColorItem,
                        secondaryColorItem, durationInMinutes)

        elif 'LightSwitch_Illuminance' == deviceName:
            return IlluminanceSensor(openHabItem)
        elif deviceName.endswith('MotionSensor'):
            return MotionSensor(openHabItem)

        return None