Exemplo n.º 1
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)
Exemplo n.º 2
0
    def setUp(self):
        scope.itemRegistry.remove(MOTION_SENSOR_SWITCH_NAME)

        self.motionSensorItem = SwitchItem(MOTION_SENSOR_SWITCH_NAME)
        scope.itemRegistry.add(self.motionSensorItem)

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

        self.motionSensor = MotionSensor(self.motionSensorItem)

        self.events = MockedEventDispatcher(scope.itemRegistry)
Exemplo n.º 3
0
class MotionSensorTest(unittest.TestCase):
    def setUp(self):
        scope.itemRegistry.remove(MOTION_SENSOR_SWITCH_NAME)

        self.motionSensorItem = SwitchItem(MOTION_SENSOR_SWITCH_NAME)
        scope.itemRegistry.add(self.motionSensorItem)

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

        self.motionSensor = MotionSensor(self.motionSensorItem)

        self.events = MockedEventDispatcher(scope.itemRegistry)

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

    def testIsOn_various_returnsExpected(self):
        self.events.sendCommand(self.motionSensorItem.getName(), "ON")
        self.assertTrue(self.motionSensor.isOn())

        self.events.sendCommand(self.motionSensorItem.getName(), "OFF")
        self.assertFalse(self.motionSensor.isOn())

    def testIsOccupied_various_returnsExpected(self):
        itemName = self.motionSensorItem.getName()

        self.events.sendCommand(itemName, "ON")
        self.motionSensor.onMotionSensorTurnedOn(self.events, itemName)
        self.assertTrue(self.motionSensor.isOccupied())

        self.events.sendCommand(self.motionSensorItem.getName(), "OFF")
        self.assertTrue(self.motionSensor.isOccupied())
Exemplo n.º 4
0
class LightTest(unittest.TestCase):
    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)

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

    def testTurnOn_lightWasOff_returnsExpected(self):
        self.light.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertEqual(scope.OnOffType.ON, self.lightItem.getState())

    def testTurnOn_lightWasAlreadyOn_timerIsRenewed(self):
        self.lightItem.setState(scope.OnOffType.ON)
        self.assertFalse(self.light._isTimerActive())

        self.light.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertEqual(scope.OnOffType.ON, self.lightItem.getState())
        self.assertTrue(self.light._isTimerActive())

    def testOnSwitchTurnedOn_validParams_timerIsTurnedOn(self):
        self.lightItem.setState(scope.OnOffType.ON)

        isProcessed = self.light.onSwitchTurnedOn(
            MockedEventDispatcher(scope.itemRegistry),
            self.lightItem.getName())
        self.assertTrue(isProcessed)
        self.assertTrue(self.light._isTimerActive())

    def testOnSwitchTurnedOn_invalidItemName_returnsFalse(self):
        isProcessed = self.light.onSwitchTurnedOn(
            MockedEventDispatcher(scope.itemRegistry), "wrong name")
        self.assertFalse(isProcessed)

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

        self.light.turnOff(MockedEventDispatcher(scope.itemRegistry))
        self.assertFalse(self.light._isTimerActive())

    def testOnSwitchTurnedOff_validParams_timerIsTurnedOn(self):
        self.lightItem.setState(scope.OnOffType.ON)
        self.light._startTimer(MockedEventDispatcher(scope.itemRegistry))

        isProcessed = self.light.onSwitchTurnedOff(
            MockedEventDispatcher(scope.itemRegistry),
            self.lightItem.getName())
        self.assertTrue(isProcessed)
        self.assertFalse(self.light._isTimerActive())

    def testOnSwitchTurnedOff_invalidItemName_returnsFalse(self):
        isProcessed = self.light.onSwitchTurnedOff(
            MockedEventDispatcher(scope.itemRegistry), "wrong name")
        self.assertFalse(isProcessed)

    def testIsLowIlluminance_noThresholdSet_returnsFalse(self):
        self.assertFalse(self.light.isLowIlluminance(10))

    def testIsLowIlluminance_currentIlluminanceNotAvailable_returnsFalse(self):
        self.light = Light(self.lightItem, 10, 50)
        self.assertFalse(self.light.isLowIlluminance(-1))

    def testIsLowIlluminance_currentIlluminanceAboveThreshold_returnsFalse(
            self):
        self.light = Light(self.lightItem, 10, 50)
        self.assertFalse(self.light.isLowIlluminance(60))

    def testIsLowIlluminance_currentIlluminanceBelowThreshold_returnsTrue(
            self):
        self.light = Light(self.lightItem, 10, 50)
        self.assertTrue(self.light.isLowIlluminance(10))

    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())
Exemplo n.º 5
0
from aaa_modules.layout_model.devices.astro_sensor import AstroSensor
from aaa_modules.layout_model.devices.dimmer import Dimmer
from aaa_modules.layout_model.devices.illuminance_sensor import IlluminanceSensor
from aaa_modules.layout_model.devices.motion_sensor import MotionSensor
from aaa_modules.layout_model.devices.plug import Plug
from aaa_modules.layout_model.devices.switch import Fan, Light

from aaa_modules.layout_model.actions.turn_on_switch import TurnOnSwitch
from aaa_modules.layout_model.actions.turn_off_adjacent_zones import TurnOffAdjacentZones

from aaa_modules.layout_model.device_test import DeviceTest

ILLUMINANCE_THRESHOLD_IN_LUX = 10
MOTION_SENSOR_SWITCH_NAME = 'TestMotionSensorName'
ITEMS = [
    SwitchItem('TestLightName'),
    SwitchItem(MOTION_SENSOR_SWITCH_NAME),
    NumberItem('IlluminanceSensorName'),
    StringItem('AstroSensorName'),
    DimmerItem('TestDimmerName'),
    SwitchItem('TestFanName'),
    SwitchItem('TestPlug'),
    NumberItem('TestPlugPower'),
]


# Unit tests for zone_manager.py.
class ZoneTest(DeviceTest):
    def setUp(self):
        super(ZoneTest, self).setUp()
Exemplo n.º 6
0
from aaa_modules.layout_model.actions.turn_on_switch import TurnOnSwitch

from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.mocked_zone_manager import MockedZoneManager
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.neighbor import Neighbor, NeighborType
from aaa_modules.layout_model.devices.astro_sensor import AstroSensor
from aaa_modules.layout_model.devices.illuminance_sensor import IlluminanceSensor
from aaa_modules.layout_model.devices.motion_sensor import MotionSensor
from aaa_modules.layout_model.devices.switch import Light

from aaa_modules.layout_model.device_test import DeviceTest

ILLUMINANCE_THRESHOLD_IN_LUX = 10
ITEMS = [
    SwitchItem('TestLightName1'),
    SwitchItem('TestLightName2'),
    NumberItem('IlluminanceSensorName'),
    SwitchItem('TestMotionSensor1'),
    SwitchItem('TestMotionSensor2'),
    SwitchItem('TestLightName3'),
]


# Unit tests for zone_manager.py.
class TurnOnSwitchTest(DeviceTest):
    def setUp(self):
        super(TurnOnSwitchTest, self).setUp()

        [
            self.lightItem1, self.lightItem2, self.illuminanceSensorItem,
Exemplo n.º 7
0
from core.jsr223 import scope
from org.eclipse.smarthome.core.library.items import SwitchItem, NumberItem
from org.eclipse.smarthome.core.library.types import DecimalType

from aaa_modules.layout_model.device_test import DeviceTest

#from aaa_modules.layout_model.devices import alarm_partition
#reload(alarm_partition)
from aaa_modules.layout_model.devices.alarm_partition import AlarmPartition
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

ITEMS = [SwitchItem('_AlarmStatus'), NumberItem('_AlarmMode')]


# Unit tests for alarm_partition.py.
class AlarmPartitionTest(DeviceTest):
    def setUp(self):
        super(AlarmPartitionTest, self).setUp()
        self.alarmPartition = AlarmPartition(self.getItems()[0],
                                             self.getItems()[1])

    def getItems(self, resetState=False):
        if resetState:
            ITEMS[0].setState(scope.OnOffType.OFF)
            ITEMS[1].setState(DecimalType(AlarmPartition.STATE_UNARMED))

        return ITEMS

    def testIsInAlarm_notInAlarm_returnsFalse(self):
        self.assertFalse(self.alarmPartition.isInAlarm())
Exemplo n.º 8
0
from org.eclipse.smarthome.core.library.items import SwitchItem, NumberItem
from org.eclipse.smarthome.core.library.types import DecimalType
from org.eclipse.smarthome.core.library.types import OnOffType

from aaa_modules.layout_model.device_test import DeviceTest

#from aaa_modules.layout_model.devices import plug
#reload(plug)
from aaa_modules.layout_model.devices.plug import Plug
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

ITEMS = [SwitchItem('_Plug'), NumberItem('_Power')]

# Unit tests for plug.py.
class PlugTest(DeviceTest):

    def setUp(self):
        super(PlugTest, self).setUp()
        self.plug = Plug(self.getItems()[0], self.getItems()[1])

    def getItems(self, resetState = False):
        if resetState:
            ITEMS[0].setState(OnOffType.OFF)
            ITEMS[1].setState(DecimalType(100))

        return ITEMS

    def testIsOn_notOn_returnsFalse(self):
        self.assertFalse(self.plug.isOn())

    def testTurnOn_withScopeEvents_returnsTrue(self):
Exemplo n.º 9
0
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.device_test import DeviceTest
from aaa_modules.layout_model.zone import Zone, ZoneEvent
from aaa_modules.layout_model.devices.astro_sensor import AstroSensor
from aaa_modules.layout_model.devices.dimmer import Dimmer
from aaa_modules.layout_model.devices.switch import Fan, Light, Switch
from aaa_modules.layout_model.devices.illuminance_sensor import IlluminanceSensor
from aaa_modules.layout_model.devices.motion_sensor import MotionSensor

from aaa_modules.layout_model.actions.turn_on_switch import TurnOnSwitch

ILLUMINANCE_THRESHOLD_IN_LUX = 8

ITEMS = [
    SwitchItem('TestLightName'),
    SwitchItem('TestMotionSensorName'),
    NumberItem('IlluminanceSensorName'),
    StringItem('AstroSensorName'),
    DimmerItem('TestDimmerName'),
    SwitchItem('TestFanName'),
]

INVALID_ITEM_NAME = 'invalid item name'


# Unit tests for zone_manager.py.
class ZoneManagerTest(DeviceTest):
    def setUp(self):
        super(ZoneManagerTest, self).setUp()
#from aaa_modules.layout_model.actions import turn_off_adjacent_zones
#reload(turn_off_adjacent_zones)
from aaa_modules.layout_model.actions.turn_off_adjacent_zones import TurnOffAdjacentZones

from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.mocked_zone_manager import MockedZoneManager
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.neighbor import Neighbor, NeighborType
from aaa_modules.layout_model.devices.switch import Fan, Light

from aaa_modules.layout_model.device_test import DeviceTest

ILLUMINANCE_THRESHOLD_IN_LUX = 10
ITEMS = [
    SwitchItem('TestLightName1'),
    SwitchItem('TestLightName2'),
    SwitchItem('TestLightName3'),
    SwitchItem('TestFanName'),
]


# Unit tests for turn_off_adjacent_zones.py
class TurnOffAdjacentZonesTest(DeviceTest):
    def setUp(self):
        super(TurnOffAdjacentZonesTest, self).setUp()

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

        self.light1 = Light(self.lightItem1, 5)
from aaa_modules.alert_manager import AlertManager
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.immutable_zone_manager import ImmutableZoneManager
from aaa_modules.layout_model.device_test import DeviceTest
from aaa_modules.layout_model.devices.alarm_partition import AlarmPartition
from aaa_modules.layout_model.devices.motion_sensor import MotionSensor
from aaa_modules.layout_model.devices.contact import Door

#from aaa_modules.layout_model.actions import arm_after_front_door_closed
#reload(arm_after_front_door_closed)
from aaa_modules.layout_model.actions.arm_after_front_door_closed import ArmAfterFrontDoorClosed

ITEMS = [SwitchItem('Door1'), SwitchItem('Door2'),
    SwitchItem('AlarmStatus'), NumberItem('_AlarmMode'),
    SwitchItem('ExternalMotionSensor'), SwitchItem('InternalMotionSensor')]

class MockZoneManager:
    def __init__(self, alarmPartition, zones):
        self.alarmPartition = alarmPartition
        self.zones = list(zones)

    def getDevicesByType(self, cls):
        return [self.alarmPartition]

    def getZones(self):
        return self.zones

# Unit tests for arm_after_front_door_closed.py.
Exemplo n.º 12
0
from org.eclipse.smarthome.core.library.items import SwitchItem

from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.device_test import DeviceTest
from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.neighbor import Neighbor, NeighborType
from aaa_modules.layout_model.mocked_zone_manager import MockedZoneManager
from aaa_modules.layout_model.zone import Zone, ZoneEvent
from aaa_modules.layout_model.devices.switch import Fan
from aaa_modules.layout_model.devices.chromecast_audio_sink import ChromeCastAudioSink
#from aaa_modules.layout_model.actions import play_music_during_shower
#reload(play_music_during_shower)
from aaa_modules.layout_model.actions.play_music_during_shower import PlayMusicDuringShower

ITEMS = [SwitchItem('Fan1')]


# Unit tests for play_music_during_shower.py.
class PlayMusicDuringShowerTest(DeviceTest):
    def setUp(self):
        self.sink = ChromeCastAudioSink('prefix', 'sinkName')
        self.action = PlayMusicDuringShower("anUrl")

        self.sink._setTestMode()

    def tearDown(self):
        pass

    def getItems(self, resetState=False):
        return ITEMS
Exemplo n.º 13
0
from org.eclipse.smarthome.core.library.items import SwitchItem

from aaa_modules import cast_manager
from aaa_modules.alert_manager import AlertManager
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.devices.gas_sensor import SmokeSensor
from aaa_modules.layout_model.device_test import DeviceTest

#from aaa_modules.layout_model.actions import alert_on_high_gas_level
#reload(alert_on_high_gas_level)
from aaa_modules.layout_model.actions.alert_on_high_gas_level import AlertOnHighGasLevel

ITEMS = [SwitchItem('gas_state'), NumberItem('gas_value'), ]

# Unit tests for alert_on_high_gas_level.py.
class AlertOnHighGasLevelTest(DeviceTest):
    def setUp(self):
        self.action = AlertOnHighGasLevel()
        self.zone1 = Zone('great room', [], Level.FIRST_FLOOR).addDevice(
                SmokeSensor(ITEMS[1], ITEMS[0])) # index reverse order intentionally

        ITEMS[0].setState(scope.OnOffType.OFF)

        AlertManager._setTestMode(True)
        AlertManager.reset()
        cast_manager._setTestMode(True)

    def tearDown(self):
from core.jsr223 import scope
from org.eclipse.smarthome.core.library.items import SwitchItem

from aaa_modules.alert_manager import AlertManager
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.zone import Zone, Level, ZoneEvent
from aaa_modules.layout_model.devices.contact import Door
from aaa_modules.layout_model.device_test import DeviceTest

#from aaa_modules.layout_model.actions import alert_on_door_left_open
#reload(alert_on_door_left_open)
from aaa_modules.layout_model.actions.alert_on_door_left_open import AlertOnExternalDoorLeftOpen

ITEMS = [SwitchItem('Door1'), SwitchItem('Door2')]


# Unit tests for alert_on_door_left_open.py.
class AlertOnExternalDoorLeftOpenTest(DeviceTest):
    def setUp(self):
        self.zone1 = Zone.createExternalZone('porch').addDevice(Door(ITEMS[0]))
        self.zone2 = Zone.createExternalZone('garage').addDevice(Door(
            ITEMS[1]))

        AlertManager._setTestMode(True)
        AlertManager.reset()

    def tearDown(self):
        AlertManager._setTestMode(False)
Exemplo n.º 15
0
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.device_test import DeviceTest
from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.mocked_zone_manager import MockedZoneManager
from aaa_modules.layout_model.zone import Zone, ZoneEvent, Level
from aaa_modules.layout_model.devices.alarm_partition import AlarmPartition
from aaa_modules.layout_model.devices.switch import Light
from aaa_modules.layout_model.devices.chromecast_audio_sink import ChromeCastAudioSink
#from aaa_modules.layout_model.actions import turn_off_devices_on_alarm_mode_change
#reload(turn_off_devices_on_alarm_mode_change)
from aaa_modules.layout_model.actions.turn_off_devices_on_alarm_mode_change import TurnOffDevicesOnAlarmModeChange

ITEMS = [
    SwitchItem('_testMotion'),
    SwitchItem('_testAlarmStatus'),
    NumberItem('_testArmMode'),
    SwitchItem('_testLight'),
    SwitchItem('_testTimer')
]


# Unit tests for turn-off-devices-on-alarm-mode-change.py.
class TurnOffDevicesOnAlarmModeChangeTest(DeviceTest):
    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])
Exemplo n.º 16
0
from aaa_modules.platform_encapsulator import PlatformEncapsulator as PE

from aaa_modules.layout_model.device_test import DeviceTest
from aaa_modules.layout_model.event_info import EventInfo
from aaa_modules.layout_model.mocked_zone_manager import MockedZoneManager
from aaa_modules.layout_model.zone import Zone, ZoneEvent, Level
from aaa_modules.layout_model.devices.alarm_partition import AlarmPartition
from aaa_modules.layout_model.devices.activity_times import ActivityTimes
from aaa_modules.layout_model.devices.chromecast_audio_sink import ChromeCastAudioSink
#from aaa_modules.layout_model.actions import simulate_daytime_presence
#reload(simulate_daytime_presence)
from aaa_modules.layout_model.actions.simulate_daytime_presence import SimulateDaytimePresence

ITEMS = [
    SwitchItem('_testMotion'),
    SwitchItem('_testAlarmStatus'),
    NumberItem('_testArmMode')
]


# Unit tests for simulate_daytime_presence.py.
class SimulateDaytimePresenceTest(DeviceTest):
    def setUp(self):
        super(SimulateDaytimePresenceTest, self).setUp()

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

        self.action = SimulateDaytimePresence("anUrl", 70, 0.1)