def test_successful_authentication(self): response_data = load_fixture("auth_success.json") responses.add(responses.POST, config.AUTH_URL, status=200, body=json.dumps(response_data), content_type="application/json") api = NuHeat("*****@*****.**", "secure-password") self.assertIsNone(api._session_id) api.authenticate() self.assertEqual(api._session_id, response_data.get("SessionId"))
def test_authentication_error(self): response_data = load_fixture("auth_error.json") responses.add(responses.POST, config.AUTH_URL, status=200, body=json.dumps(response_data), content_type="application/json") api = NuHeat("*****@*****.**", "secure-password") with self.assertRaises(Exception) as _: api.authenticate() self.assertIsNone(api._session_id)
from nuheat import NuHeat # Initalize an API session with your login credentials api = NuHeat("https://www.mythermostat.info/api", "<email>", "<pwd>") api.authenticate() thermostat = api.get_thermostat("<serial>") current = thermostat.celsius target = thermostat.target_celsius heating = thermostat.heating online = thermostat.online serial = thermostat.serial_number
def test_init_with_session(self): existing_session_id = "passed-session" api = NuHeat("*****@*****.**", "secure-password", existing_session_id) self.assertEqual(api._session_id, existing_session_id) api.authenticate()