Example #1
0
 def test_should_send_correct_color_temperature_values_to_wink_api(self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True, color_kelvin=arbitrary_kelvin_color)
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('color_temperature', sent_data['desired_state'].get('color_model'))
     self.assertEquals(arbitrary_kelvin_color, sent_data['desired_state'].get('color_temperature'))
Example #2
0
 def test_device_id_should_be_number(self):
     with open('{}/api_responses/light_bulb.json'.format(os.path.dirname(__file__))) as light_file:
         response_dict = json.load(light_file)
     light = response_dict.get('data')[0]
     wink_light = WinkBulb(light, self.api_interface)
     device_id = wink_light.device_id()
     self.assertRegex(device_id, "^[0-9]{4,6}$")
Example #3
0
 def test_device_id_should_be_number(self):
     with open('{}/api_responses/light_bulb.json'.format(
             os.path.dirname(__file__))) as light_file:
         response_dict = json.load(light_file)
     light = response_dict.get('data')[0]
     wink_light = WinkBulb(light, self.api_interface)
     device_id = wink_light.device_id()
     self.assertRegex(device_id, "^[0-9]{4,6}$")
Example #4
0
 def test_should_only_send_color_xy_if_both_color_xy_and_color_temperature_are_given(self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True, color_kelvin=arbitrary_kelvin_color, color_xy=[0, 1])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('color_temperature', sent_data['desired_state'].get('color_model'))
     self.assertNotIn('color_x', sent_data['desired_state'])
     self.assertNotIn('color_y', sent_data['desired_state'])
Example #5
0
 def test_should_send_correct_color_xy_values_to_wink_api(self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     color_x = 0.75
     color_y = 0.25
     bulb.set_state(True, color_xy=[color_x, color_y])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals(color_x, sent_data.get('desired_state', {}).get('color_x'))
     self.assertEquals(color_y, sent_data.get('desired_state', {}).get('color_y'))
     self.assertEquals('xy', sent_data['desired_state'].get('color_model'))
Example #6
0
 def test_should_send_correct_color_temperature_values_to_wink_api(
         self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True, color_kelvin=arbitrary_kelvin_color)
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('color_temperature',
                       sent_data['desired_state'].get('color_model'))
     self.assertEquals(arbitrary_kelvin_color,
                       sent_data['desired_state'].get('color_temperature'))
Example #7
0
 def test_should_send_correct_color_xy_values_to_wink_api(self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     color_x = 0.75
     color_y = 0.25
     bulb.set_state(True, color_xy=[color_x, color_y])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals(color_x,
                       sent_data.get('desired_state', {}).get('color_x'))
     self.assertEquals(color_y,
                       sent_data.get('desired_state', {}).get('color_y'))
     self.assertEquals('xy', sent_data['desired_state'].get('color_model'))
Example #8
0
 def test_should_send_color_temperature_to_api_if_color_temp_is_provided_and_bulb_only_supports_temperature(self):
     bulb = WinkBulb({
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["color_temperature"]}]
         }
     }, self.api_interface)
     color_kelvin = 4000
     bulb.set_state(True, color_kelvin=color_kelvin)
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(color_kelvin, sent_desired_state.get('color_temperature'))
Example #9
0
 def test_should_only_send_color_hsb_if_both_color_hsb_and_color_temperature_are_given(self, put_mock):
     bulb = WinkBulb({
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["hsb"]}]
         }
     }, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True, color_kelvin=arbitrary_kelvin_color, color_hue_saturation=[0, 1])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
     self.assertNotIn('color_temperature', sent_data['desired_state'])
Example #10
0
 def test_should_only_send_color_xy_if_both_color_xy_and_color_temperature_are_given(
         self, put_mock):
     bulb = WinkBulb({}, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True,
                    color_kelvin=arbitrary_kelvin_color,
                    color_xy=[0, 1])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('color_temperature',
                       sent_data['desired_state'].get('color_model'))
     self.assertNotIn('color_x', sent_data['desired_state'])
     self.assertNotIn('color_y', sent_data['desired_state'])
Example #11
0
 def test_should_send_current_hue_and_saturation_to_api_if_hue_and_sat_are_provided_and_bulb_only_supports_hue_sat(self):
     bulb = WinkBulb({
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["hsb"]}]
         }
     }, self.api_interface)
     hue = 0.2
     saturation = 0.3
     bulb.set_state(True, color_hue_saturation=[hue, saturation])
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(hue, sent_desired_state.get('hue'))
     self.assertEquals(saturation, sent_desired_state.get('saturation'))
Example #12
0
 def test_should_send_correct_color_hsb_values_to_wink_api(self, put_mock):
     bulb = WinkBulb({
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["hsb"]}]
         }
     }, self.api_interface)
     hue = 0.75
     saturation = 0.25
     bulb.set_state(True, color_hue_saturation=[hue, saturation])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals(hue, sent_data.get('desired_state', {}).get('hue'))
     self.assertEquals(saturation, sent_data.get('desired_state', {}).get('saturation'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
Example #13
0
 def test_should_send_current_brightness_to_api_if_only_color_temperature_is_provided_and_bulb_only_supports_temperature(self):
     original_brightness = 0.5
     bulb = WinkBulb({
         'last_reading': {
             'desired_brightness': original_brightness
         },
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["color_temperature"]}]
         }
     }, self.api_interface)
     bulb.set_state(True, color_kelvin=4000)
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(original_brightness, sent_desired_state.get('brightness'))
Example #14
0
 def test_should_send_original_brightness_when_only_xy_color_given_and_only_hue_saturation_supported(self):
     original_brightness = 0.5
     bulb = WinkBulb({
         'last_reading': {
             'desired_brightness': original_brightness
         },
         'capabilities': {
             'fields': [{'field': 'color_model',
                        'choices':["hsb"]}]
         }
     }, self.api_interface)
     bulb.set_state(True, color_xy=[0.5, 0.5])
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(original_brightness, sent_desired_state.get('brightness'))
Example #15
0
def build_device(device_state_as_json, api_interface):

    new_object = None

    # pylint: disable=redefined-variable-type
    # These objects all share the same base class: WinkDevice

    if "light_bulb_id" in device_state_as_json:
        new_object = WinkBulb(device_state_as_json, api_interface)
    elif "sensor_pod_id" in device_state_as_json:
        new_object = WinkSensorPod(device_state_as_json, api_interface)
    elif "binary_switch_id" in device_state_as_json:
        new_object = WinkBinarySwitch(device_state_as_json, api_interface)
    elif "outlet_id" in device_state_as_json:
        new_object = WinkPowerStripOutlet(device_state_as_json, api_interface)
    elif "lock_id" in device_state_as_json:
        new_object = WinkLock(device_state_as_json, api_interface)
    elif "eggtray_id" in device_state_as_json:
        new_object = WinkEggTray(device_state_as_json, api_interface)
    elif "garage_door_id" in device_state_as_json:
        new_object = WinkGarageDoor(device_state_as_json, api_interface)
    elif "siren_id" in device_state_as_json:
        new_object = WinkSiren(device_state_as_json, api_interface)

    return new_object or WinkDevice(device_state_as_json, api_interface)
Example #16
0
 def test_should_send_color_temperature_to_api_if_color_temp_is_provided_and_bulb_only_supports_temperature(
         self):
     bulb = WinkBulb(
         {
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["color_temperature"]
                 }]
             }
         }, self.api_interface)
     color_kelvin = 4000
     bulb.set_state(True, color_kelvin=color_kelvin)
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(color_kelvin,
                       sent_desired_state.get('color_temperature'))
Example #17
0
 def test_should_send_correct_color_hsb_values_to_wink_api(self, put_mock):
     bulb = WinkBulb(
         {
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["hsb"]
                 }]
             }
         }, self.api_interface)
     hue = 0.75
     saturation = 0.25
     bulb.set_state(True, color_hue_saturation=[hue, saturation])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals(hue, sent_data.get('desired_state', {}).get('hue'))
     self.assertEquals(saturation,
                       sent_data.get('desired_state', {}).get('saturation'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
Example #18
0
 def test_should_send_current_hue_and_saturation_to_api_if_hue_and_sat_are_provided_and_bulb_only_supports_hue_sat(
         self):
     bulb = WinkBulb(
         {
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["hsb"]
                 }]
             }
         }, self.api_interface)
     hue = 0.2
     saturation = 0.3
     bulb.set_state(True, color_hue_saturation=[hue, saturation])
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(hue, sent_desired_state.get('hue'))
     self.assertEquals(saturation, sent_desired_state.get('saturation'))
Example #19
0
 def test_should_only_send_color_hsb_if_both_color_hsb_and_color_temperature_are_given(
         self, put_mock):
     bulb = WinkBulb(
         {
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["hsb"]
                 }]
             }
         }, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True,
                    color_kelvin=arbitrary_kelvin_color,
                    color_hue_saturation=[0, 1])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
     self.assertNotIn('color_temperature', sent_data['desired_state'])
Example #20
0
 def test_should_only_send_color_hsb_if_both_color_hsb_and_color_temperature_are_given(self, put_mock):
     bulb = WinkBulb({
         "capabilities": {
             "fields": [
                 {
                     "field": "hue"
                 },
                 {
                     "field": "saturation"
                 }
             ],
             "color_changeable": True
         }
     }, self.api_interface)
     arbitrary_kelvin_color = 4950
     bulb.set_state(True, color_kelvin=arbitrary_kelvin_color, color_hue_saturation=[0, 1])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
     self.assertNotIn('color_temperature', sent_data['desired_state'])
Example #21
0
 def test_should_send_original_brightness_when_only_xy_color_given_and_only_hue_saturation_supported(
         self):
     original_brightness = 0.5
     bulb = WinkBulb(
         {
             'last_reading': {
                 'desired_brightness': original_brightness
             },
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["hsb"]
                 }]
             }
         }, self.api_interface)
     bulb.set_state(True, color_xy=[0.5, 0.5])
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(original_brightness,
                       sent_desired_state.get('brightness'))
Example #22
0
 def test_should_send_current_brightness_to_api_if_only_color_temperature_is_provided_and_bulb_only_supports_hue_sat(
         self):
     original_brightness = 0.5
     bulb = WinkBulb(
         {
             'last_reading': {
                 'desired_brightness': original_brightness
             },
             'capabilities': {
                 'fields': [{
                     'field': 'color_model',
                     'choices': ["hsb"]
                 }]
             }
         }, self.api_interface)
     bulb.set_state(True, color_kelvin=4000)
     set_state_mock = self.api_interface.set_device_state
     sent_desired_state = set_state_mock.call_args[0][1]['desired_state']
     self.assertEquals(original_brightness,
                       sent_desired_state.get('brightness'))
Example #23
0
 def test_should_send_correct_color_hsb_values_to_wink_api(self, put_mock):
     bulb = WinkBulb({
         "capabilities": {
             "fields": [
                 {
                     "field": "hue"
                 },
                 {
                     "field": "saturation"
                 }
             ],
             "color_changeable": True
         }
     }, self.api_interface)
     hue = 0.75
     saturation = 0.25
     bulb.set_state(True, color_hue_saturation=[hue, saturation])
     sent_data = json.loads(put_mock.call_args[1].get('data'))
     self.assertEquals(hue, sent_data.get('desired_state', {}).get('hue'))
     self.assertEquals(saturation, sent_data.get('desired_state', {}).get('saturation'))
     self.assertEquals('hsb', sent_data['desired_state'].get('color_model'))
Example #24
0
def build_device(device_state_as_json, api_interface):

    new_object = None

    # These objects all share the same base class: WinkDevice

    if "light_bulb_id" in device_state_as_json:
        new_object = WinkBulb(device_state_as_json, api_interface)
    elif "sensor_pod_id" in device_state_as_json:
        new_object = WinkSensorPod(device_state_as_json, api_interface)
    elif "binary_switch_id" in device_state_as_json:
        new_object = WinkBinarySwitch(device_state_as_json, api_interface)
    elif "outlet_id" in device_state_as_json:
        new_object = WinkPowerStripOutlet(device_state_as_json, api_interface)
    elif "lock_id" in device_state_as_json:
        new_object = WinkLock(device_state_as_json, api_interface)
    elif "eggtray_id" in device_state_as_json:
        new_object = WinkEggTray(device_state_as_json, api_interface)
    elif "garage_door_id" in device_state_as_json:
        new_object = WinkGarageDoor(device_state_as_json, api_interface)
    elif "shade_id" in device_state_as_json:
        new_object = WinkShade(device_state_as_json, api_interface)
    elif "siren_id" in device_state_as_json:
        new_object = WinkSiren(device_state_as_json, api_interface)
    elif "key_id" in device_state_as_json:
        new_object = WinkKey(device_state_as_json, api_interface)
    elif "thermostat_id" in device_state_as_json:
        new_object = WinkThermostat(device_state_as_json, api_interface)
    elif "fan_id" in device_state_as_json:
        new_object = WinkFan(device_state_as_json, api_interface)
    # This must be at the bottom most devices have a hub_id listed
    # as their associated hub.
    elif "hub_id" in device_state_as_json:
        new_object = WinkHub(device_state_as_json, api_interface)

    return new_object or WinkDevice(device_state_as_json, api_interface)