Пример #1
0
 def test_thermostat_has_fan(self):
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/sensi_thermostat.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     thermostat = get_devices_from_response_dict(response_dict, device_types.THERMOSTAT)[0]
     self.assertTrue(thermostat.has_fan())
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/ecobee_thermostat.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     thermostat = get_devices_from_response_dict(response_dict, device_types.THERMOSTAT)[0]
     self.assertTrue(thermostat.has_fan())
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/nest.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     thermostat = get_devices_from_response_dict(response_dict, device_types.THERMOSTAT)[0]
     self.assertFalse(thermostat.has_fan())
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/go_control_thermostat.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     thermostat = get_devices_from_response_dict(response_dict, device_types.THERMOSTAT)[0]
     self.assertTrue(thermostat.has_fan())
Пример #2
0
 def test_switch_groups_are_created_correctly(self):
     all_devices = os.listdir('{}/api_responses/groups/'.format(
         os.path.dirname(__file__)))
     device_list = []
     for json_file in all_devices:
         if os.path.isfile('{}/api_responses/groups/{}'.format(
                 os.path.dirname(__file__), json_file)):
             _json_file = open('{}/api_responses/groups/{}'.format(
                 os.path.dirname(__file__), json_file))
             device_list.append(json.load(_json_file))
             _json_file.close()
     JSON_DATA["data"] = device_list
     all_groups = get_devices_from_response_dict(JSON_DATA,
                                                 device_types.GROUP)
     self.assertEqual(3, len(all_groups))
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/groups/switch_group.json'.format(
         os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     groups = get_devices_from_response_dict(response_dict,
                                             device_types.GROUP)
     self.assertEqual(1, len(groups))
     self.assertTrue(isinstance(groups[0], WinkBinarySwitchGroup))
Пример #3
0
 def test_should_convert_humidity_to_percentage(self):
     with open('{}/api_responses/wink_relay_sensor.json'.format(
             os.path.dirname(__file__))) as relay_file:
         response_dict = json.load(relay_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
     self.assertEqual(devices[0].humidity_percentage(), 69)
Пример #4
0
 def test_gocontrol_motion_sensor_should_be_identified(self):
     response = ApiResponseJSONLoader('motion_sensor_gocontrol.json').load()
     devices = get_devices_from_response_dict(
         response, DEVICE_ID_KEYS[device_types.SENSOR_POD])
     self.assertEqual(2, len(devices))
     self.assertIsInstance(devices[1], WinkMotionSensor)
     self.assertIsInstance(devices[0], WinkTemperatureSensor)
Пример #5
0
 def test_ge_switch_should_be_identified(self):
     response = ApiResponseJSONLoader(
         'light_switch_ge_jasco_z_wave.json').load()
     devices = get_devices_from_response_dict(
         response, DEVICE_ID_KEYS[device_types.BINARY_SWITCH])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkBinarySwitch)
Пример #6
0
    def test_pubnub_key_and_channel_should_be_none(self):
        with open('{}/api_responses/lock.json'.format(os.path.dirname(__file__))) as lock_file:
            response_dict = json.load(lock_file)
        device = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.LOCK])[0]

        self.assertIsNone(device.pubnub_key)
        self.assertIsNone(device.pubnub_channel)
Пример #7
0
    def test_cloud_clock_json_parses_into_the_correct_objects(self):
        with open('{}/api_responses/nimbus.json'.format(
                os.path.dirname(__file__))) as nimbus_file:
            response_dict = json.load(nimbus_file)
        response_dict = {"data": [response_dict]}
        devices = get_devices_from_response_dict(response_dict,
                                                 device_types.CLOUD_CLOCK)

        self.assertEqual(len(devices), 8)
        cloud_clock = devices[0]
        self.assertTrue(isinstance(devices[0], WinkCloudClock))

        self.assertTrue(isinstance(devices[1], WinkCloudClockDial))
        self.assertTrue(isinstance(devices[2], WinkCloudClockDial))
        self.assertTrue(isinstance(devices[3], WinkCloudClockDial))
        self.assertTrue(isinstance(devices[4], WinkCloudClockDial))
        self.assertTrue(isinstance(devices[5], WinkCloudClockAlarm))
        self.assertTrue(isinstance(devices[6], WinkCloudClockAlarm))
        self.assertTrue(isinstance(devices[7], WinkCloudClockAlarm))
        self.assertEqual(devices[1].parent, cloud_clock)
        self.assertEqual(devices[2].parent, cloud_clock)
        self.assertEqual(devices[3].parent, cloud_clock)
        self.assertEqual(devices[4].parent, cloud_clock)
        self.assertEqual(devices[5].parent, cloud_clock)
        self.assertEqual(devices[6].parent, cloud_clock)
        self.assertEqual(devices[7].parent, cloud_clock)
Пример #8
0
 def test_firmware_version_is_not_none(self):
     devices = get_devices_from_response_dict(self.response_dict, device_types.HUB)
     for device in devices:
         if device.manufacturer_device_model() == "philips":
             continue
         else:
             self.assertIsNotNone(device.firmware_version())
Пример #9
0
 def test_all_devices_manufacturer_device_id_state_is_valid(self):
     devices = get_devices_from_response_dict(
         self.response_dict, device_types.ALL_SUPPORTED_DEVICES)
     skip_types = [
         WinkKey, WinkPowerStrip, WinkPowerStripOutlet,
         WinkPorkfolioBalanceSensor, WinkPorkfolioNose, WinkSiren,
         WinkEggtray, WinkRemote, WinkButton, WinkAirConditioner,
         WinkPropaneTank
     ]
     skip_manufactuer_device_models = [
         "linear_wadwaz_1", "linear_wapirz_1", "aeon_labs_dsb45_zwus",
         "wink_hub", "wink_hub2", "sylvania_sylvania_ct", "ge_bulb",
         "quirky_ge_spotter", "schlage_zwave_lock",
         "home_decorators_home_decorators_fan", "sylvania_sylvania_rgbw",
         "somfy_bali", "wink_relay_sensor", "wink_project_one",
         "kidde_smoke_alarm", "wink_relay_switch", "leaksmart_valve",
         "home_decorators_home_decorators_light_bulb"
     ]
     skip_names = [
         "GoControl Thermostat", "GE Zwave Switch", "New Shortcut",
         "Test robot"
     ]
     for device in devices:
         if device.name() in skip_names:
             self.assertIsNone(device.manufacturer_device_id())
         elif device.manufacturer_device_model(
         ) in skip_manufactuer_device_models:
             self.assertIsNone(device.manufacturer_device_id())
         elif type(device) in skip_types:
             self.assertIsNone(device.manufacturer_device_id())
         else:
             self.assertIsNotNone(device.manufacturer_device_id())
Пример #10
0
 def test_should_handle_power_strip_response(self):
     with open('{}/api_responses/power_strip.json'.format(os.path.dirname(__file__))) as powerstrip_file:
         response_dict = json.load(powerstrip_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.POWER_STRIP])
     self.assertEqual(2, len(devices))
     self.assertIsInstance(devices[0], WinkPowerStripOutlet)
     self.assertIsInstance(devices[1], WinkPowerStripOutlet)
Пример #11
0
 def test_should_handle_porkfolio_response(self):
     with open('{}/api_responses/porkfolio.json'.format(os.path.dirname(__file__))) as porkfolio_file:
         response_dict = json.load(porkfolio_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.PIGGY_BANK])
     self.assertEqual(2, len(devices))
     self.assertIsInstance(devices[0], WinkCurrencySensor)
     self.assertIsInstance(devices[1], WinkPorkfolioNose)
Пример #12
0
 def test_unit_is_usd(self):
     devices = get_devices_from_response_dict(self.response_dict,
                                              device_types.PIGGY_BANK)
     self.assertEqual(len(devices), 2)
     for device in devices:
         if isinstance(device, WinkPorkfolioBalanceSensor):
             self.assertEqual(device.unit(), "USD")
Пример #13
0
 def test_gocontrol_motion_sensor_should_be_identified(self):
     response = ApiResponseJSONLoader('motion_sensor_gocontrol.json').load()
     devices = get_devices_from_response_dict(response,
                                              DEVICE_ID_KEYS[
                                                  device_types.SENSOR_POD])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkSensorPod)
Пример #14
0
 def test_all_devices_battery_is_valid(self):
     devices = get_devices_from_response_dict(
         self.response_dict, device_types.ALL_SUPPORTED_DEVICES)
     skip_types = [
         WinkFan, WinkGeZwaveFan, WinkPorkfolioBalanceSensor,
         WinkPorkfolioNose, WinkBinarySwitch, WinkHub, WinkLightBulb,
         WinkThermostat, WinkKey, WinkPowerStrip, WinkPowerStripOutlet,
         WinkRemote, WinkShade, WinkSprinkler, WinkButton, WinkGang,
         WinkCanaryCamera, WinkAirConditioner, WinkScene, WinkRobot,
         WinkWaterHeater
     ]
     for device in devices:
         if device.manufacturer_device_model() == "leaksmart_valve":
             self.assertIsNotNone(device.battery_level())
         elif type(device) in skip_types:
             self.assertIsNone(device.battery_level())
         elif device.manufacturer_device_model() == "wink_relay_sensor":
             self.assertIsNone(device.battery_level())
         elif device.device_manufacturer() == "dropcam":
             self.assertIsNone(device.battery_level())
         elif device.model_name() == "Nest Cam":
             self.assertIsNone(device.battery_level())
         elif device._last_reading.get('external_power'):
             self.assertIsNone(device.battery_level())
         else:
             self.assertIsNotNone(device.battery_level())
Пример #15
0
 def test_should_handle_binary_switch_response(self):
     with open('{}/api_responses/binary_switch.json'.format(
             os.path.dirname(__file__))) as binary_switch_file:
         response_dict = json.load(binary_switch_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.BINARY_SWITCH])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkBinarySwitch)
Пример #16
0
    def test_current_min_set_point(self):
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertEqual(22.22222222222222, thermostat.current_min_set_point())
Пример #17
0
 def test_device_id_should_be_number(self):
     with open('{}/api_responses/smoke_detector.json'.format(
             os.path.dirname(__file__))) as smoke_detector_file:
         response_dict = json.load(smoke_detector_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.SMOKE_DETECTOR])
     device_id = devices[0].device_id()
     self.assertRegex(device_id, "^[0-9]{4,6}")
Пример #18
0
 def test_objectprefix_should_be_correct(self):
     with open('{}/api_responses/porkfolio.json'.format(os.path.dirname(__file__))) as porkfolio_file:
         response_dict = json.load(porkfolio_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.PIGGY_BANK])
     objectprefix = devices[0].objectprefix
     self.assertRegex(objectprefix, "piggy_bank")
     objectprefix = devices[1].objectprefix
     self.assertRegex(objectprefix, "piggy_bank")
Пример #19
0
 def test_objectprefix_should_be_correct(self):
     with open('{}/api_responses/smoke_detector.json'.format(os.path.dirname(__file__))) as smoke_detector_file:
         response_dict = json.load(smoke_detector_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SMOKE_DETECTOR])
     objectprefix = devices[0].objectprefix
     self.assertRegex(objectprefix, "smoke_detectors")
     objectprefix = devices[1].objectprefix
     self.assertRegex(objectprefix, "smoke_detectors")
Пример #20
0
    def test_should_be_cool_only_for_current_hvac_mode(self):
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertEqual('cool_only', thermostat.current_hvac_mode())
Пример #21
0
 def test_should_handle_siren_response(self):
     with open('{}/api_responses/siren.json'.format(
             os.path.dirname(__file__))) as siren_file:
         response_dict = json.load(siren_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.SIREN])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkSiren)
Пример #22
0
 def test_should_handle_garage_door_opener_response(self):
     with open('{}/api_responses/garage_door.json'.format(
             os.path.dirname(__file__))) as garage_door_file:
         response_dict = json.load(garage_door_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.GARAGE_DOOR])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkGarageDoor)
Пример #23
0
 def test_fan_timer_range(self):
     fan = get_devices_from_response_dict(self.response_dict,
                                          device_types.FAN)[0]
     has_timer_range = fan.fan_timer_range()
     self.assertEqual(len(has_timer_range), 2)
     times = [0, 65535]
     for time in has_timer_range:
         self.assertTrue(time in times)
Пример #24
0
 def test_fan_directions(self):
     fan = get_devices_from_response_dict(self.response_dict,
                                          device_types.FAN)[0]
     has_directions = fan.fan_directions()
     self.assertEqual(len(has_directions), 2)
     directions = ['forward', 'reverse']
     for direction in has_directions:
         self.assertTrue(direction in directions)
Пример #25
0
    def test_should_be_false_if_response_doesnt_contains_aux_capabilities(self):
        with open('{}/api_responses/nest.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertFalse('aux' in thermostat.hvac_modes())
Пример #26
0
 def test_should_handle_sensor_pod_response(self):
     with open('{}/api_responses/binary_sensor.json'.format(
             os.path.dirname(__file__))) as binary_sensor_file:
         response_dict = json.load(binary_sensor_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkSensorPod)
Пример #27
0
    def test_should_be_true_if_thermostat_fan_is_on(self):
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertTrue(thermostat.fan_on())
Пример #28
0
 def test_should_handle_egg_tray_response(self):
     with open('{}/api_responses/eggtray.json'.format(
             os.path.dirname(__file__))) as eggtray_file:
         response_dict = json.load(eggtray_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.EGG_TRAY])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkEggTray)
Пример #29
0
    def test_state_should_be_false(self):
        with open('{}/api_responses/ge_zwave_switch.json'.format(os.path.dirname(__file__))) as binary_switch_file:
            response_dict = json.load(binary_switch_file)
        response_dict = {"data": [response_dict]}
        devices = get_devices_from_response_dict(response_dict, device_types.BINARY_SWITCH)

        switch = devices[0]
        self.assertFalse(switch.state())
Пример #30
0
 def test_should_show_powered_state_as_false_if_device_is_disconnected(
         self):
     with open('{}/api_responses/power_strip.json'.format(
             os.path.dirname(__file__))) as powerstrip_file:
         response_dict = json.load(powerstrip_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.POWER_STRIP])
     self.assertFalse(devices[0].state())
Пример #31
0
 def test_should_handle_light_bulb_response(self):
     with open('{}/api_responses/light_bulb.json'.format(
             os.path.dirname(__file__))) as light_file:
         response_dict = json.load(light_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.LIGHT_BULB])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkBulb)
Пример #32
0
 def test_should_hub_response(self):
     with open('{}/api_responses/v1_hub.json'.format(
             os.path.dirname(__file__))) as hub_file:
         response_dict = json.load(hub_file)
     devices = get_devices_from_response_dict(
         response_dict, DEVICE_ID_KEYS[device_types.HUB])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkHub)
Пример #33
0
 def test_fan_speeds(self):
     fan = get_devices_from_response_dict(self.response_dict,
                                          device_types.FAN)[0]
     has_speeds = fan.fan_speeds()
     self.assertEqual(len(has_speeds), 3)
     speeds = ['low', 'medium', 'high']
     for speed in has_speeds:
         self.assertTrue(speed in speeds)
Пример #34
0
 def test_unit_is_valid(self):
     devices = get_devices_from_response_dict(self.response_dict,
                                              device_types.SENSOR_POD)
     for device in devices:
         if device.unit_type() == "boolean":
             self.assertIsNone(device.unit())
         else:
             self.assertIsNotNone(device.unit())
Пример #35
0
    def test_available_should_be_true(self):
        with open('{}/api_responses/scene.json'.format(os.path.dirname(__file__))) as scene_file:
            response_dict = json.load(scene_file)
        response_dict = {"data": [response_dict]}
        devices = get_devices_from_response_dict(response_dict, device_types.SCENE)

        scene = devices[0]
        self.assertTrue(scene.available())
Пример #36
0
 def test_buttons_press_is_false(self):
     devices = get_devices_from_response_dict(self.response_dict,
                                              device_types.REMOTE)
     remote = devices[0]
     self.assertFalse(remote.button_on_pressed())
     self.assertFalse(remote.button_off_pressed())
     self.assertFalse(remote.button_up_pressed())
     self.assertFalse(remote.button_down_pressed())
Пример #37
0
    def test_battery_level_should_return_float(self):
        with open('{}/api_responses/quirky_spotter_2.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])

        for sensor in sensors:
            self.assertEqual(sensor.battery_level, 0.86)
Пример #38
0
    def test_current_humidifier_mode(self):
        # sensi.json been faked to add in the humidifier_mode field for testing.
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertEqual('auto', thermostat.current_humidifier_mode())
Пример #39
0
    def test_brightness_should_have_correct_value(self):
        with open('{}/api_responses/quirky_spotter.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
        """:type : list of WinkBrightnessSensor"""
        brightness_sensor = [sensor for sensor in sensors if sensor.capability() is WinkBrightnessSensor.CAPABILITY][0]
        expected_brightness = 1
        self.assertEquals(expected_brightness, brightness_sensor.brightness_percentage())
Пример #40
0
 def test_eggs(self):
     devices = get_devices_from_response_dict(self.response_dict,
                                              device_types.EGGTRAY)
     for device in devices:
         for egg in device.eggs():
             try:
                 val = float(egg)
             except ValueError:
                 self.fail("test_eggs raised ValueError unexpectedly.")
Пример #41
0
    def test_device_id_should_start_with_a_number(self):
        with open('{}/api_responses/quirky_spotter.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])

        for sensor in sensors:
            device_id = sensor.device_id()
            self.assertRegex(device_id, "^[0-9]{4,6}")
Пример #42
0
    def test_device_id_should_be_number(self):
        with open('{}/api_responses/porkfolio.json'.format(os.path.dirname(__file__))) as porkfolio_file:
            response_dict = json.load(porkfolio_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.PIGGY_BANK])
        device_id = devices[0].device_id()
        self.assertRegex(device_id, "^[0-9]{4,6}")

        device_id = devices[1].device_id()
        self.assertRegex(device_id, "^[0-9]{4,6}")
Пример #43
0
 def test_ac_modes(self):
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/quirky_aros.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     ac = get_devices_from_response_dict(response_dict, device_types.AIR_CONDITIONER)[0]
     self.assertEqual(ac.modes(), ["auto_eco", "cool_only", "fan_only"])
Пример #44
0
    def test_should_be_true_if_thermostat_has_detected_occupancy(self):
        # sensi.json been faked to add in the occupied field for testing.
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertTrue(thermostat.occupied())
Пример #45
0
 def test_ac_max_set_point(self):
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/quirky_aros.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     ac = get_devices_from_response_dict(response_dict, device_types.AIR_CONDITIONER)[0]
     self.assertEqual(ac.current_max_set_point(), 20.0)
Пример #46
0
 def test_should_handle_relay_response(self):
     with open('{}/api_responses/wink_relay_sensor.json'.format(os.path.dirname(__file__))) as relay_file:
         response_dict = json.load(relay_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
     self.assertEqual(4, len(devices))
     self.assertIsInstance(devices[0], WinkHumiditySensor)
     self.assertIsInstance(devices[1], WinkTemperatureSensor)
     self.assertIsInstance(devices[2], WinkPresenceSensor)
     self.assertIsInstance(devices[3], WinkProximitySensor)
Пример #47
0
 def test_schedule_enabled(self):
     device_list = []
     response_dict = {}
     _json_file = open('{}/api_responses/quirky_aros.json'.format(os.path.dirname(__file__)))
     device_list.append(json.load(_json_file))
     _json_file.close()
     response_dict["data"] = device_list
     ac = get_devices_from_response_dict(response_dict, device_types.AIR_CONDITIONER)[0]
     self.assertTrue(ac.schedule_enabled())
Пример #48
0
    def test_temperature_should_have_correct_value(self):
        with open('{}/api_responses/quirky_spotter.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
        """:type : list of WinkTemperatureSensor"""
        temp_sensor = [sensor for sensor in sensors if sensor.capability() is WinkTemperatureSensor.CAPABILITY][0]
        expected_temperature = 5
        self.assertEquals(expected_temperature, temp_sensor.temperature_float())
Пример #49
0
    def test_vibration_should_have_correct_value(self):
        with open('{}/api_responses/quirky_spotter.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
        """:type : list of WinkVibrationPresenceSensor"""
        vibration_sensor = [sensor for sensor in sensors if sensor.capability() is WinkVibrationPresenceSensor.CAPABILITY][0]
        expected_vibrartion_presence = False
        self.assertEquals(expected_vibrartion_presence, vibration_sensor.vibration_boolean())
Пример #50
0
    def test_should_be_false_if_response_does_not_contain_rgb_capabilities(self):
        with open('{}/api_responses/rgb_absent.json'.format(os.path.dirname(__file__))) as light_file:
            response_dict = json.load(light_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.LIGHT_BULB])

        bulb = devices[0]
        """ :type bulb: pywink.devices.standard.WinkBulb """
        supports_rgb = bulb.supports_rgb()
        self.assertFalse(supports_rgb,
                        msg="Expected rgb to be un-supported")
Пример #51
0
    def test_should_be_true_if_response_contains_xy_capabilities(self):
        with open('{}/api_responses/xy_present.json'.format(os.path.dirname(__file__))) as light_file:
            response_dict = json.load(light_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.LIGHT_BULB])

        bulb = devices[0]
        """ :type bulb: pywink.devices.standard.WinkBulb """
        supports_xy = bulb.supports_xy_color()
        self.assertTrue(supports_xy,
                        msg="Expected xy to be supported")
Пример #52
0
    def test_current_smart_temperature(self):
        # This result is only present on ecobee thermostats, the sensi.json has
        # been faked to add in the smart_temperature field for testing.
        with open('{}/api_responses/sensi.json'.format(os.path.dirname(__file__))) as thermostat_file:
            response_dict = json.load(thermostat_file)
        devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.THERMOSTAT])

        thermostat = devices[0]
        """ :type thermostat: pywink.devices.standard.WinkThermostat """
        self.assertEqual(20.555555555555557, thermostat.current_smart_temperature())
Пример #53
0
 def test_should_handle_smoke_detector_response(self):
     with open('{}/api_responses/smoke_detector.json'.format(os.path.dirname(__file__))) as smoke_detector_file:
         response_dict = json.load(smoke_detector_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SMOKE_DETECTOR])
     self.assertEqual(2, len(devices))
     smoke = devices[0]
     co = devices[1]
     self.assertIsInstance(smoke, WinkSmokeDetector)
     self.assertIsInstance(co, WinkCoDetector)
     self.assertFalse(smoke.smoke_detected_boolean())
     self.assertTrue(co.co_detected_boolean())
Пример #54
0
    def test_humidity_is_percentage_after_update(self):
        with open('{}/api_responses/quirky_spotter.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
        """:type : list of WinkHumiditySensor"""
        humidity_sensor = [sensor for sensor in sensors if sensor.capability() is WinkHumiditySensor.CAPABILITY][0]

        with open('{}/api_responses/quirky_spotter_pubnub.json'.format(os.path.dirname(__file__))) as spotter_file:
            update_response_dict = json.load(spotter_file)

        humidity_sensor.pubnub_update(update_response_dict)
        expected_humidity = 24
        self.assertEquals(expected_humidity, humidity_sensor.humidity_percentage())
Пример #55
0
 def test_should_handle_siren_response(self):
     with open('{}/api_responses/siren.json'.format(os.path.dirname(__file__))) as siren_file:
         response_dict = json.load(siren_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SIREN])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkSiren)
Пример #56
0
 def test_should_handle_egg_tray_response(self):
     with open('{}/api_responses/eggtray.json'.format(os.path.dirname(__file__))) as eggtray_file:
         response_dict = json.load(eggtray_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.EGG_TRAY])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkEggTray)
Пример #57
0
 def test_should_show_powered_state_as_false_if_device_is_disconnected(self):
     with open('{}/api_responses/power_strip.json'.format(os.path.dirname(__file__))) as powerstrip_file:
         response_dict = json.load(powerstrip_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.POWER_STRIP])
     self.assertFalse(devices[0].state())
Пример #58
0
 def test_should_handle_garage_door_opener_response(self):
     with open('{}/api_responses/garage_door.json'.format(os.path.dirname(__file__))) as garage_door_file:
         response_dict = json.load(garage_door_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.GARAGE_DOOR])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkGarageDoor)
Пример #59
0
    def test_alternative_quirky_spotter_api_response_should_create_one_primary_sensor_and_five_subsensors(self):
        with open('{}/api_responses/quirky_spotter_2.json'.format(os.path.dirname(__file__))) as spotter_file:
            response_dict = json.load(spotter_file)

        sensors = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.SENSOR_POD])
        self.assertEquals(1 + 5, len(sensors))
Пример #60
0
 def test_should_handle_light_bulb_response(self):
     with open('{}/api_responses/light_bulb.json'.format(os.path.dirname(__file__))) as light_file:
         response_dict = json.load(light_file)
     devices = get_devices_from_response_dict(response_dict, DEVICE_ID_KEYS[device_types.LIGHT_BULB])
     self.assertEqual(1, len(devices))
     self.assertIsInstance(devices[0], WinkBulb)