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
def test_10a_details_fail(self, caplog, api_mock): """Test 10A get_details with Code>0.""" self.mock_api.return_value = BAD_10A_LIST out = VeSyncOutlet10A(DEV_LIST_DETAIL_EU, self.vesync_obj) out.get_details() assert len(caplog.records) == 1 assert 'details' in caplog.text
def test_10a_no_details(self, details, id, caplog, api_mock): """Test 10A details return with no details and code=0""" bad_10a_details = {"code": 0, "deviceStatus": "on"} self.mock_api.return_value = (bad_10a_details, 200) out = VeSyncOutlet10A(details, self.vesync_obj) out.get_details() assert len(caplog.records) == 2
def test_10a_details(self, api_mock): """Test 10A get_details().""" self.mock_api.return_value = CORRECT_10A_DETAILS outlet = VeSyncOutlet10A(DEV_LIST_DETAIL_US, self.vesync_obj) outlet.get_details() dev_details = outlet.details assert outlet.device_status == 'on' assert type(dev_details) == dict assert dev_details['active_time'] == 1 assert dev_details['energy'] == 1 assert dev_details['power'] == '1' assert dev_details['voltage'] == '1' assert outlet.power == 1 assert outlet.voltage == 1
def test_history_fail(self, caplog, api_mock): """Test 15A energy failure.""" bad_history = {"code": 1} self.mock_api.return_value = (bad_history, 200) out = VeSyncOutlet10A(DEV_LIST_DETAIL_US, self.vesync_obj) out.update_energy() assert len(caplog.records) == 1 assert 'weekly' in caplog.text caplog.clear() out.get_monthly_energy() assert len(caplog.records) == 1 assert 'monthly' in caplog.text caplog.clear() out.get_yearly_energy() assert len(caplog.records) == 1 assert 'yearly' in caplog.text
def test_10a_yearly(self, api_mock): """Test 10A get_yearly_energy.""" self.mock_api.return_value = ENERGY_HISTORY out = VeSyncOutlet10A(DEV_LIST_DETAIL_US, self.vesync_obj) out.get_yearly_energy() body = helpers.req_body(self.vesync_obj, 'energy_year') body['uuid'] = out.uuid self.mock_api.assert_called_with('/10a/v1/device/energyyear', 'post', headers=helpers.req_headers( self.vesync_obj), json=body) energy_dict = out.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] assert out.yearly_energy_total == 1
def test_10a_onoff(self, caplog, api_mock): """Test 10A Device On/Off Methods.""" self.mock_api.return_value = ({"code": 0}, 200) out = VeSyncOutlet10A(DEV_LIST_DETAIL_EU, self.vesync_obj) head = helpers.req_headers(self.vesync_obj) body = helpers.req_body(self.vesync_obj, 'devicestatus') body['status'] = 'on' body['uuid'] = out.uuid on = out.turn_on() self.mock_api.assert_called_with('/10a/v1/device/devicestatus', 'put', headers=head, json=body) assert on off = out.turn_off() body['status'] = 'off' self.mock_api.assert_called_with('/10a/v1/device/devicestatus', 'put', headers=head, json=body) assert off
def test_10a_onoff_fail(self, api_mock): """Test 10A On/Off Fail with Code>0.""" self.mock_api.return_value = ({"code": 1}, 400) out = VeSyncOutlet10A(DEV_LIST_DETAIL_US, self.vesync_obj) assert not out.turn_on() assert not out.turn_off()