Beispiel #1
0
    def setUp(self):
        scope.itemRegistry.remove(DIMMER_NAME)
        scope.itemRegistry.remove(TIMER_NAME)

        self.dimmerItem = DimmerItem(DIMMER_NAME)
        scope.itemRegistry.add(self.dimmerItem)

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

        self.dimmer = Dimmer(self.dimmerItem, 10, 100, "0-23:59")
Beispiel #2
0
    def testTurnOn_lightWasOffWithinDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        dimLevel = 5
        nextHour = 0 if hourOfDay == 23 else hourOfDay + 1  # 24-hour wrapping
        timeRanges = "{}-{}".format(hourOfDay, nextHour)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(dimLevel, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())
Beispiel #3
0
    def testTurnOn_lightWasOffOutsideDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        if hourOfDay >= 22:  # handle 24-hour wrapping
            hourOfDay = 0

        dimLevel = 5
        timeRanges = "{}-{}".format(hourOfDay + 2, hourOfDay + 2)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(100, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())
Beispiel #4
0
    def setUp(self):
        super(ZoneManagerTest, self).setUp()

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

        self.illuminanceSensor = IlluminanceSensor(self.illuminanceSensorItem)
        self.light = 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.fanItem, 2)

        self.zm = ZoneManager()
Beispiel #5
0
class DimmerTest(unittest.TestCase):
    def setUp(self):
        scope.itemRegistry.remove(DIMMER_NAME)
        scope.itemRegistry.remove(TIMER_NAME)

        self.dimmerItem = DimmerItem(DIMMER_NAME)
        scope.itemRegistry.add(self.dimmerItem)

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

        self.dimmer = Dimmer(self.dimmerItem, 10, 100, "0-23:59")

    def tearDown(self):
        scope.itemRegistry.remove(self.dimmerItem.getName())

    def testTurnOn_lightWasOffOutsideDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        if hourOfDay >= 22:  # handle 24-hour wrapping
            hourOfDay = 0

        dimLevel = 5
        timeRanges = "{}-{}".format(hourOfDay + 2, hourOfDay + 2)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(100, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())

    def testTurnOn_lightWasOffWithinDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        dimLevel = 5
        nextHour = 0 if hourOfDay == 23 else hourOfDay + 1  # 24-hour wrapping
        timeRanges = "{}-{}".format(hourOfDay, nextHour)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(dimLevel, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())

    def testTurnOn_lightWasAlreadyOn_timerIsRenewed(self):
        self.dimmerItem.setState(PercentType(100))

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertTrue(self.dimmer._isTimerActive())

    def testTurnOff_bothLightAndTimerOn_timerIsRenewed(self):
        self.dimmerItem.setState(PercentType(0))

        self.dimmer.turnOff(MockedEventDispatcher(scope.itemRegistry))
        self.assertFalse(self.dimmer.isOn())
Beispiel #6
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