Esempio n. 1
0
    def test_display_func(self, caplog, api_mock):
        """Test display function outputs text."""
        self.vesync_obj.outlets.append(
            VeSyncOutdoorPlug(json_vals.LIST_CONF_OUTDOOR_1, self.vesync_obj))
        self.vesync_obj.outlets.append(
            VeSyncOutlet10A(json_vals.LIST_CONF_10AUS, self.vesync_obj))
        self.vesync_obj.outlets.append(
            VeSyncOutlet15A(json_vals.LIST_CONF_15A, self.vesync_obj))
        self.vesync_obj.outlets.append(
            VeSyncOutlet7A(json_vals.LIST_CONF_7A, self.vesync_obj))
        self.vesync_obj.switches.append(
            VeSyncWallSwitch(json_vals.LIST_CONF_WS, self.vesync_obj))
        self.vesync_obj.fans.append(
            VeSyncAir131(json_vals.LIST_CONF_AIR, self.vesync_obj))
        self.vesync_obj.bulbs.append(
            VeSyncBulbESL100(json_vals.LIST_CONF_ESL100, self.vesync_obj))

        dev_list = [
            self.vesync_obj.outlets, self.vesync_obj.switches,
            self.vesync_obj.fans, self.vesync_obj.bulbs
        ]

        for device in chain(*dev_list):
            device.display()

        assert len(caplog.records) == 0
Esempio n. 2
0
 def test_7a_no_details(self, caplog, api_mock):
     """Test 7A outlet details response with unknown keys."""
     bad_7a_details = {'wrongdetails': 'on'}
     self.mock_api.return_value = (bad_7a_details, 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_details()
     assert len(caplog.records) == 1
Esempio n. 3
0
 def test_7a_no_details(self, caplog, api_mock):
     bad_7a_details = {
         "wrongdetails": "on"
     }
     self.mock_api.return_value = (bad_7a_details, 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_details()
     assert len(caplog.records) == 2
Esempio n. 4
0
 def test_7a_details(self, api_mock):
     """Test get_details() method for 7A outlet."""
     self.mock_api.return_value = CORRECT_7A_DETAILS
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_details()
     dev_details = vswitch7a.details
     assert vswitch7a.device_status == 'on'
     assert type(dev_details) == dict
     assert dev_details['active_time'] == 1
     assert dev_details['energy'] == 1
     assert vswitch7a.power == 1
     assert vswitch7a.voltage == 1
Esempio n. 5
0
 def test_7a_no_devstatus(self, caplog, api_mock):
     bad_7a_details = {
         "deviceImg": "",
         "activeTime": 1,
         "energy": 1,
         "power": "1A:1A",
         "voltage": "1A:1A"
     }
     self.mock_api.return_value = (bad_7a_details, 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_details()
     assert len(caplog.records) == 2
     assert 'details' in caplog.text
Esempio n. 6
0
 def test_7a_yearly(self, api_mock):
     self.mock_api.return_value = ENERGY_HISTORY
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_yearly_energy()
     self.mock_api.assert_called_with(
         '/v1/device/' + vswitch7a.cid + '/energy/year',
         'get',
         headers=helpers.req_headers(self.vesync_obj))
     energy_dict = vswitch7a.energy['year']
     assert energy_dict['energy_consumption_of_today'] == 1
     assert energy_dict['cost_per_kwh'] == 1
     assert energy_dict['max_energy'] == 1
     assert energy_dict['total_energy'] == 1
     assert energy_dict['data'] == [1, 1]
Esempio n. 7
0
 def test_7a_onoff(self, caplog, api_mock):
     self.mock_api.return_value = ("response", 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     on = vswitch7a.turn_on()
     head = helpers.req_headers(self.vesync_obj)
     self.mock_api.assert_called_with(
         '/v1/wifi-switch-1.3/' + vswitch7a.cid + '/status/on', 'put',
         headers=head)
     assert on
     off = vswitch7a.turn_off()
     self.mock_api.assert_called_with(
             '/v1/wifi-switch-1.3/' + vswitch7a.cid + '/status/off', 'put',
             headers=head)
     assert off
Esempio n. 8
0
 def test_7a_no_devstatus(self, caplog, api_mock):
     """Test 7A outlet details response with no device status key."""
     bad_7a_details = {
         'deviceImg': '',
         'activeTime': 1,
         'energy': 1,
         'power': '1A:1A',
         'voltage': '1A:1A',
     }
     self.mock_api.return_value = (bad_7a_details, 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.get_details()
     assert len(caplog.records) == 1
     assert 'details' in caplog.text
Esempio n. 9
0
 def test_history_fail(self, caplog, api_mock):
     bad_history = {"code": 1}
     self.mock_api.return_value = (bad_history, 200)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     vswitch7a.update_energy()
     assert len(caplog.records) == 2
     assert 'weekly' in caplog.text
     caplog.clear()
     vswitch7a.get_monthly_energy()
     assert len(caplog.records) == 2
     assert 'monthly' in caplog.text
     caplog.clear()
     vswitch7a.get_yearly_energy()
     assert len(caplog.records) == 2
     assert 'yearly' in caplog.text
Esempio n. 10
0
 def test_7a_onoff_fail(self, api_mock):
     """Test 7A outlet on/off methods that fail."""
     self.mock_api.return_value = ('response', 400)
     vswitch7a = VeSyncOutlet7A(DEV_LIST_DETAIL, self.vesync_obj)
     assert not vswitch7a.turn_on()
     assert not vswitch7a.turn_off()