Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
import contants from home assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas55555 committed Mar 14, 2021
1 parent 645230d commit 75c954b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 6 additions & 3 deletions custom_components/husqvarna_automower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
from homeassistant.core import Config, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import (
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_USERNAME,
CONF_API_KEY,
CONF_PASSWORD,
CONF_USERNAME,
)

from .const import (
DOMAIN,
PLATFORMS,
STARTUP_MESSAGE,
Expand Down
17 changes: 13 additions & 4 deletions custom_components/husqvarna_automower/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow to add the integration via the UI."""
from homeassistant.const import CONF_ACCESS_TOKEN
import logging
import time
from collections import OrderedDict
Expand All @@ -7,8 +8,13 @@
from aioautomower import GetAccessToken, GetMowerData
from homeassistant import config_entries
from homeassistant.core import callback

from .const import CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME, DOMAIN, HUSQVARNA_URL
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_USERNAME,
CONF_API_KEY,
CONF_PASSWORD,
)
from .const import DOMAIN, HUSQVARNA_URL

CONF_ID = "unique_id"

Expand Down Expand Up @@ -43,11 +49,12 @@ async def async_step_user(self, user_input=None):

errors = {}
try:
await try_connection(
config_data = await try_connection(
user_input[CONF_USERNAME],
user_input[CONF_PASSWORD],
user_input[CONF_API_KEY],
)
_LOGGER.debug("Config_data %s", config_data)
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "auth"
Expand All @@ -65,6 +72,7 @@ async def async_step_user(self, user_input=None):
CONF_USERNAME: user_input[CONF_USERNAME],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_API_KEY: user_input[CONF_API_KEY],
CONF_ACCESS_TOKEN: config_data,
},
)

Expand All @@ -74,7 +82,6 @@ async def try_connection(username, password, api_key):
_LOGGER.debug("Trying to connect to Husqvarna")
auth_api = GetAccessToken(api_key, username, password)
access_token_raw = await auth_api.async_get_access_token()
_LOGGER.debug("Access token raw: %s", access_token_raw)
_LOGGER.debug("Access token status: %s", access_token_raw["status"])
if access_token_raw["status"] == 200:
_LOGGER.debug("Connected with the Authentication API")
Expand Down Expand Up @@ -103,6 +110,8 @@ async def try_connection(username, password, api_key):
else:
_LOGGER.error("Error %s", mower_data["status"])
raise Exception

_LOGGER.debug("Mower data: %s", mower_data)
_LOGGER.debug("Successfully connected Authentication and Automower Connect API")
time.sleep(5)
return access_token
2 changes: 0 additions & 2 deletions custom_components/husqvarna_automower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

# Configuration and options
CONF_ENABLED = "enabled"
CONF_USERNAME = "username"
CONF_PASSWORD = "password"
CONF_API_KEY = "api_key"


Expand Down

0 comments on commit 75c954b

Please sign in to comment.