def test_parse(self):
        tahoma = Protocol("", "", unittest=1 )
        tahoma._getSetup(SetupInput) # only for unit tests

        self.assertEqual(tahoma.location["postalCode"], "90210")
        self.assertTrue(tahoma.gateway[0]["alive"])
        self.assertEqual(tahoma.gateway[0]["connectivity"]["protocolVersion"], "8")
        self.assertEqual(len(tahoma.getDevices()), 6)
        device = tahoma.getDevice("hue://1234-1234-1234/123456789012/lights/1")
        self.assertEqual(device.activeStates["core:CieColorSpaceYState"], 0.2792)
    def test_multiEventsWithImplicitUpdate(self):

        eventData = [{
            "name": "ExecutionStateChangedEvent",
            "setupOID": "123456-1234-1234-1234-1234567890",
            "execId": "12345678-1234-1234-1234-123456782012",
            "newState": "4",
            "ownerKey": "1234-1234-1234",
            "type": "5",
            "subType": "-1",
            "oldState": "2"
        }, {
            "name": "DeviceStateChangedEvent",
            "setupOID": "123456-1234-1234-1234-1234567890",
            "deviceURL": "io://1234-1234-1234/12345644",
            "deviceStates": [{
                "name": "core:ClosureState",
                "value": "12"
            }, {
                "name": "core:OpenClosedState",
                "value": "open"
            }]
        }]

        tahoma = Protocol("", "", unittest=1 )
        tahoma._getSetup(SetupInput) # only for unit tests

        device = tahoma.getDevice("io://1234-1234-1234/12345644")
        self.assertEqual(device.activeStates["core:ClosureState"], 100)
        self.assertEqual(device.activeStates["core:OpenClosedState"], "closed")

        events = tahoma._getEvents(eventData)
        self.assertEqual(len(events), 2)
        self.assertTrue(isinstance(events[0], ExecutionStateChangedEvent))
        self.assertEqual(events[0].execId, "12345678-1234-1234-1234-123456782012")
        self.assertEqual(events[0].state, EventState.Completed)

        self.assertTrue(isinstance(events[1], DeviceStateChangedEvent))
        self.assertEqual(events[1].deviceURL, "io://1234-1234-1234/12345644")

        self.assertEqual(device.activeStates["core:ClosureState"], 12)
        self.assertEqual(device.activeStates["core:OpenClosedState"], "open")
Example #3
0
    def test_requestBuilding(self):
        tahoma = Protocol("", "", unittest=1 )
        tahoma._getSetup(SetupInput) # only for unit tests

        light = tahoma.getDevice("hue://1234-1234-1234/123456789012/lights/1")
        window = tahoma.getDevice("io://1234-1234-1234/12345644")

        request = tahoma._createGetStateRequest( [ light, window ] )

        shouldBe = '''[{"deviceURL": "hue://1234-1234-1234/123456789012/lights/1","states": [{"name": "core:CieColorSpaceXState"},{"name": "core:CieColorSpaceYState"},{"name": "core:ColorHueState"},{"name": "core:ColorSaturationState"},{"name": "core:LightIntensityState"},{"name": "core:NameState"},{"name": "core:OnOffState"},{"name": "hue:HueColorModeState"}]},{"deviceURL": "io://1234-1234-1234/12345644","states": [{"name": "core:ClosureState"},{"name": "core:NameState"},{"name": "core:OpenClosedState"},{"name": "core:PriorityLockTimerState"}]}]'''

        self.assertEqual(request, shouldBe)
    def test_parse(self):
        tahoma = Protocol("", "", unittest=1)
        tahoma._getSetup(SetupInput)  # only for unit tests

        self.assertEqual(tahoma.location["postalCode"], "90210")
        self.assertTrue(tahoma.gateway[0]["alive"])
        self.assertEqual(tahoma.gateway[0]["connectivity"]["protocolVersion"],
                         "8")
        self.assertEqual(len(tahoma.getDevices()), 6)
        device = tahoma.getDevice("hue://1234-1234-1234/123456789012/lights/1")
        self.assertEqual(device.activeStates["core:CieColorSpaceYState"],
                         0.2792)
Example #5
0
    def test_multiEventsWithImplicitUpdate(self):

        eventData = [{
            "name": "ExecutionStateChangedEvent",
            "setupOID": "123456-1234-1234-1234-1234567890",
            "execId": "12345678-1234-1234-1234-123456782012",
            "newState": "4",
            "ownerKey": "1234-1234-1234",
            "type": "5",
            "subType": "-1",
            "oldState": "2"
        }, {
            "name":
            "DeviceStateChangedEvent",
            "setupOID":
            "123456-1234-1234-1234-1234567890",
            "deviceURL":
            "io://1234-1234-1234/12345644",
            "deviceStates": [{
                "name": "core:ClosureState",
                "value": "12"
            }, {
                "name": "core:OpenClosedState",
                "value": "open"
            }]
        }]

        tahoma = Protocol("", "", unittest=1)
        tahoma._getSetup(SetupInput)  # only for unit tests

        device = tahoma.getDevice("io://1234-1234-1234/12345644")
        self.assertEqual(device.activeStates["core:ClosureState"], 100)
        self.assertEqual(device.activeStates["core:OpenClosedState"], "closed")

        events = tahoma._getEvents(eventData)
        self.assertEqual(len(events), 2)
        self.assertTrue(isinstance(events[0], ExecutionStateChangedEvent))
        self.assertEqual(events[0].execId,
                         "12345678-1234-1234-1234-123456782012")
        self.assertEqual(events[0].state, EventState.Completed)

        self.assertTrue(isinstance(events[1], DeviceStateChangedEvent))
        self.assertEqual(events[1].deviceURL, "io://1234-1234-1234/12345644")

        self.assertEqual(device.activeStates["core:ClosureState"], 12)
        self.assertEqual(device.activeStates["core:OpenClosedState"], "open")
Example #6
0
 def test_getUser(self):
     tahoma = Protocol(_USER, _PW)
     user = tahoma.getUser()
     self.assertTrue( user['firstName'] != "" )
Example #7
0
 def test_getStates(self):
     tahoma = Protocol(_USER, _PW)
     tahoma.getSetup()
     self.assertTrue( len(tahoma.getDevices()) > 0)
     tahoma.getStates(None)
Example #8
0
 def test_getActionGroups(self):
     tahoma = Protocol(_USER, _PW)
     groups = tahoma.getActionGroups()
     self.assertTrue( len(groups) > 0)
Example #9
0
    def test_applyChanges(self):
        tahoma = Protocol("", "", unittest=1 )
        tahoma._getSetup(SetupInput) # only for unit tests

        changeData = {
	"devices": [{
		"label": "Light name",
		"deviceURL": "hue://1234-1234-1234/123456789012/lights/1",
		"shortcut": False,
		"states": [{
			"name": "core:ColorHueState",
			"type": 1,
			"value": 265
		}, {
			"name": "core:ColorSaturationState",
			"type": 1,
			"value": 44
		}, {
			"name": "core:CieColorSpaceXState",
			"type": 2,
			"value": 0.432
		}, {
			"name": "core:CieColorSpaceYState",
			"type": 2,
			"value": 0.2792
		}, {
			"name": "hue:HueColorModeState",
			"type": 3,
			"value": "hs"
		}, {
			"name": "core:NameState",
			"type": 3,
			"value": "Light name"
		}, {
			"name": "core:OnOffState",
			"type": 3,
			"value": "on"
		}, {
			"name": "core:LightIntensityState",
			"type": 1,
			"value": 20
		}],
		"available": False,
		"enabled": False,
		"type": 1
	}, {
		"label": "window2",
		"deviceURL": "io://1234-1234-1234/12345644",
		"shortcut": False,
		"states": [{
			"name": "core:NameState",
			"type": 3,
			"value": "window2"
		}, {
			"name": "core:PriorityLockTimerState",
			"type": 1,
			"value": 0
		}, {
			"name": "core:ClosureState",
			"type": 1,
			"value": 22
		}, {
			"name": "core:OpenClosedState",
			"type": 3,
			"value": "open"
		}],
		"available": False,
		"enabled": False,
		"type": 1
	}]
}

        light = tahoma.getDevice("hue://1234-1234-1234/123456789012/lights/1")
        window = tahoma.getDevice("io://1234-1234-1234/12345644")

        self.assertEqual( light.activeStates["core:CieColorSpaceXState"], 0.3505 )
        self.assertEqual( light.activeStates["core:LightIntensityState"], 0 )
        self.assertEqual( light.activeStates["core:OnOffState"], "off" )

        self.assertEqual( window.activeStates["core:ClosureState"], 100 )
        self.assertEqual( window.activeStates["core:OpenClosedState"], "closed" )

        tahoma._getStates(changeData) # only for unit tests

        self.assertEqual( light.activeStates["core:CieColorSpaceXState"], 0.432 )
        self.assertEqual( light.activeStates["core:LightIntensityState"], 20 )
        self.assertEqual( light.activeStates["core:OnOffState"], "on" )

        self.assertEqual( window.activeStates["core:ClosureState"], 22 )
        self.assertEqual( window.activeStates["core:OpenClosedState"], "open" )
Example #10
0
 def test_getUser(self):
     tahoma = Protocol(_USER, _PW)
     user = tahoma.getUser()
     self.assertTrue(user['firstName'] != "")
Example #11
0
 def test_getStates(self):
     tahoma = Protocol(_USER, _PW)
     tahoma.getSetup()
     self.assertTrue(len(tahoma.getDevices()) > 0)
     tahoma.getStates(None)
Example #12
0
 def test_getActionGroups(self):
     tahoma = Protocol(_USER, _PW)
     groups = tahoma.getActionGroups()
     self.assertTrue(len(groups) > 0)