示例#1
0
class TestLight(TestCase):
    def setUp(self):
        self.hue = Hue(ip=ip, api_key=api_key)

    def test_light_set_on(self):
        light = self.hue.get_light(5)
        light.set_on(True)

    def test_light_set_bri(self):
        light = self.hue.get_light(5)

        with self.assertRaises(Exception) as context:
            light.set_bri(Bri.MAX.value + 1)

        self.assertTrue(isinstance(context.exception, ValueError))

        light.set_bri(Bri.MAX.value)

    def test_light_set_ct(self):
        light = self.hue.get_light(5)

        light.set_ct(Ct.MAX.value)

    def test_lights_set_alert(self):
        light = self.hue.get_light(5)

        with self.assertRaises(Exception) as context:
            light.set_alert('select')

        self.assertTrue(isinstance(context.exception, TypeError))

    def test_lights_set_alert_wrong_parameter(self):
        light = self.hue.get_light(5)
        light.set_alert(Alert.SELECT)
示例#2
0
class TestTemperatureSensor(TestCase):
    def setUp(self):
        self.hue = Hue(ip=ip, api_key=api_key)

    def test_get_temperature(self):
        temperature_sensor = self.hue.get_sensor(86)
        temperature = temperature_sensor.get_temperature()
        print(temperature_sensor.get_temperature())
        print(temperature_sensor.get_temperature_in_celsius())
        print(temperature_sensor.get_temperature_formatted())
示例#3
0
    def setUp(self):
        self.hue = Hue(ip=ip, api_key=api_key)

        self.dummy_links = [
            '/scenes/7FQzspPLCTwjAsL', '/rules/4', '/sensors/66', '/groups/1'
        ]
        self.dummy_resourcelink = Resourcelink(self.hue, 'dummy_id', 10013,
                                               'dumy dimmer switch',
                                               'Dimmer switch',
                                               self.dummy_links)
 def __init__(self,
              notification=False,
              room_id=0,
              temperature_notification=False,
              temperature_sensor=None,
              temperature_limit=2100):
     self.hue = Hue.Hue(ip=ip, api_key=api_key)
     self.notification = notification
     self.temperature_notification = temperature_notification
     self.room = self.hue.get_group(room_id)
     self.room_all = self.hue.get_group(0)
     if temperature_sensor is not None:
         self.temperature = self.hue.get_sensor(
             temperature_sensor).get_temperature()
     self.temperature_limit = temperature_limit
示例#5
0
class TestGroup(TestCase):
    def setUp(self):
        self.hue = Hue(ip=ip, api_key=api_key)

    def test_group_set_on(self):
        group = self.hue.get_group(1)
        group.set_on(True)

    def test_group_set_bri(self):
        group = self.hue.get_group(1)

        with self.assertRaises(Exception) as context:
            group.set_bri(int(Bri.MAX.value + 1))

        print(context.exception)
        self.assertTrue(isinstance(context.exception, ValueError))

        group.set_bri(Bri.MAX.value)

    def test_group_set_ct(self):
        group = self.hue.get_group(1)

        with self.assertRaises(Exception) as context:
            group.set_ct(int(Ct.MAX.value + 1))

        self.assertTrue(isinstance(context.exception, ValueError))

        group.set_ct(200)

    def test_group_set_alert(self):
        group = self.hue.get_group(1)
        group.set_alert(Alert.SELECT)

    def test_group_set_alert_wrong_parameter(self):
        group = self.hue.get_group(1)

        with self.assertRaises(Exception) as context:
            group.set_alert('select')

        self.assertTrue(isinstance(context.exception, TypeError))

    def test_group_set_scene(self):
        group = self.hue.get_group(1)
        scenes = self.hue.get_scenes_for_group(group)

        group.set_scene(scenes[1])
示例#6
0
 def setUp(self):
     self.hue = Hue(ip=ip, api_key=api_key)
示例#7
0
    current_time = time.time()
    current_time_formatted = time.strftime('%H:%M',
                                           time.localtime(current_time))

    f = open("last_triggered.txt", "r")
    last_triggered = float(f.read())

    f = open("last_triggered.txt", "w")
    f.write(str(current_time))
    f.close()

    last_triggered_plus_four_hours = last_triggered + (4 * 60)

    return last_triggered, last_triggered_plus_four_hours, current_time_formatted


if __name__ == '__main__':
    hue = Hue.Hue(ip=ip, api_key=hue_api_key)
    temperature = hue.get_sensor(86).get_temperature()

    last_triggered, last_triggered_plus_four_hours, current_time_formatted = getTimes(
    )
    temperature_limit = 2100

    if '06.00' <= current_time_formatted <= '21.30':
        if last_triggered < time.time():
            if temperature > temperature_limit:
                title = 'Temperature is {} °C'.format(temperature / 100)

                send_request(title, "Shortcuts", "now")
示例#8
0
import RPi.GPIO as GPIO

import time

from config import ip, api_key
from huePyApi import Hue

debounce_time = 0.22
long_press_time = 0.8

index = 0

hue = Hue.Hue(ip=ip, api_key=api_key)
group_0 = hue.get_group(0)
group_5 = hue.get_group(5)
scenes_dimmer = hue.get_resourcelink(1063).get_linked_scenes()
scenes_dimmer.reverse()
scenes_dimmer.append('8CwvoHEQe02ATlp')  # (schlafen II)


class Button:
    id_counter = 0

    def __init__(self, title, gpioPin, btnAction):
        self.id = Button.id_counter
        self.title = title
        self.gpioPin = gpioPin
        self.btnAction = btnAction

        Button.id_counter += 1
示例#9
0
class TestHue(TestCase):
    def setUp(self):
        self.hue = Hue(ip=ip, api_key=api_key)

    # groups
    def test_get_all_groups(self):
        groups = self.hue.get_all_groups()
        print(groups)

    def test_get_group(self):
        group = self.hue.get_group(1)
        print(group)

    # lights
    def test_get_all_lights(self):
        lights = self.hue.get_all_lights()
        print(lights)

    def test_get_light(self):
        light = self.hue.get_light(26)
        print(light)

    # scenes
    def test_get_all_scenes(self):
        scenes = self.hue.get_all_scenes()
        print(scenes)

    def test_that_scene_id_length_always_is_15(self):
        scenes = self.hue.get_all_scenes()
        for scene in scenes:
            assert 15 == len(scene.scene_id)

    def test_get_scene(self):
        scene = self.hue.get_scene('7FQzspPLCTwjAsL')
        print(scene)

    def test_get_scenes_for_group(self):
        group = self.hue.get_group(1)
        scenes = self.hue.get_scenes_for_group(group)
        print(scenes)

    # resourcelinks
    def test_get_all_resourcelinks(self):
        resourcelinks = self.hue.get_all_resourcelinks()
        print(resourcelinks)

    def test_get_resourcelink(self):
        scene = self.hue.get_resourcelink(5287)
        print(scene)

    # sensors
    def test_get_all_sensors(self):
        sensors = self.hue.get_all_sensors()

        for sensor in sensors:
            print(sensor)

    def test_get_sensors_for_modelid(self):
        sensors = self.hue.get_sensors_for_modelid(SensorModel.HUE_HOMEAWAY)

        for sensor in sensors:
            print(sensor)
            # print(sensor.name, '-', sensor.modelid)

    def test_get_sensor(self):
        sensor = self.hue.get_sensor(64)
        print(sensor.config)
        print(sensor.get_battery())
        print(sensor)

    def test_test_extern_method(self):
        self.hue.test_extern_method()