diff --git a/pyheatpump/config.py b/pyheatpump/config.py index b50f758..c22955d 100644 --- a/pyheatpump/config.py +++ b/pyheatpump/config.py @@ -57,10 +57,6 @@ def save_config(): config.write(conf_file) -def get_mac(): - return get_config_dict()['heatpump', 'mac_address'] - - def mac_address_init(): from netifaces import gateways, ifaddresses, AF_INET, AF_LINK @@ -112,6 +108,10 @@ async def config_route(request, *args, **kwargs): return await set_config(request) +def get_mac(): + return config.get('heatpump','mac_address') + + async def mac_route(request, *args, **kwargs): if request['method'] == 'GET': return PlainTextResponse(get_mac()) diff --git a/tests/test_config.py b/tests/test_config.py index 191162b..d2f183e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -81,12 +81,24 @@ def test_set_config(tmpconf): def test_mac_address(testdir, tmpconf): + c = TestClient(app) + _, tmpconf = mkstemp() + CONFIG_FILES.append(tmpconf) + mac_address = mac_address_init() assert type(get_config_dict()) == dict - d_config =get_config_dict() + d_config = get_config_dict() assert d_config['heatpump']['mac_address'] == mac_address + resp = c.get('/mac') + assert resp.status_code == 200 + mac_address = resp.content.decode() + + assert d_config['heatpump']['mac_address'] == mac_address + + + def test_last_update(testdir, tmpconf): c = TestClient(app)