Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sHedC authored Jan 3, 2024
2 parents 4179e80 + b9595e0 commit 70af9b2
Show file tree
Hide file tree
Showing 20 changed files with 413 additions and 107 deletions.
20 changes: 12 additions & 8 deletions .devcontainer-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
"vscode": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance",
"mikestead.dotenv",
"ms-python.black-formatter",
"charliermarsh.ruff",
"github.vscode-pull-request-github",
"charliermarsh.ruff"
"mikestead.dotenv",
"ryanluker.vscode-coverage-gutters"
],
"settings": {
"files.eol": "\n",
"files.associations": {
"*.yaml": "home-assistant"
},
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.experiments.enabled": false,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"extensions.ignoreRecommendations": true,
"files.trimTrailingWhitespace": true
}
}
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
ignore:
# Dependabot should not update Home Assistant as that should match the homeassistant key in hacs.json
- dependency-name: "homeassistant"
5 changes: 5 additions & 0 deletions configuration-template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# https://www.home-assistant.io/integrations/default_config/
default_config:

# Enable to initiate debugging in Home Assistant Runtime
debugpy:
start: false
wait: false

# https://www.home-assistant.io/integrations/logger/
logger:
default: warning
Expand Down
34 changes: 31 additions & 3 deletions custom_components/ambrogio_robot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .api_firebase import AmbrogioRobotFirebaseAPI, AmbrogioRobotException
from .api.firebase import AmbrogioRobotFirebaseAPI, AmbrogioRobotException
from .const import (
API_KEY,
DOMAIN,
)
from .api import AmbrogioRobotApiClient
from .api.api import AmbrogioRobotApiClient
from .coordinator import AmbrogioDataUpdateCoordinator

PLATFORMS: list[Platform] = [
Expand All @@ -41,12 +42,39 @@ async def async_setup(


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
implementation = (
await config_entry_oauth2_flow.async_get_config_entry_implementation(
hass, entry
)
)

session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)

# If using a requests-based API lib
# hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.ConfigEntryAuth(
# hass, session
# )

# If using an aiohttp-based API lib
# hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.AsyncConfigEntryAuth(
# aiohttp_client.async_get_clientsession(hass), session
#

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


async def async_setup_entry2(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
hass.data.setdefault(DOMAIN, {})

# Get or update the list of robots from Firebase
try:
api_firebase = AmbrogioRobotFirebaseAPI(async_get_clientsession(hass))
api_firebase = AmbrogioRobotFirebaseAPI(
aiohttp_client.async_get_clientsession(hass)
)
tokens = await api_firebase.verify_password(
entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD]
)
Expand Down
1 change: 1 addition & 0 deletions custom_components/ambrogio_robot/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""API Module."""
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import aiohttp
import async_timeout

from .const import LOGGER
from ..const import LOGGER


class AmbrogioRobotApiClientError(Exception):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

_LOGGER: logging.Logger = logging.getLogger(__name__)

GOOGLEAPIS_URL = "https://www.googleapis.com"
VERIFY_PASSWORD = "/identitytoolkit/v3/relyingparty/verifyPassword"
GOOGLEAPIS_URL = "https://identitytoolkit.googleapis.com"
VERIFY_PASSWORD = "/v1/accounts:signInWithPassword"

FIREBASE_URL = "wss://centrosistemi-ambrogioremote.firebaseio.com"
FIREBASE_DB = "centrosistemi-ambrogioremote"
FIREBASE_VER = "5"

APP_ID = "AIzaSyCUGSbVrwZ3X7BHU6oiUSmdzQwx-QXypUI"
API_KEY = "AIzaSyCUGSbVrwZ3X7BHU6oiUSmdzQwx-QXypUI"


class AmbrogioRobotException(Exception):
Expand Down Expand Up @@ -49,7 +49,7 @@ async def verify_password(self, email: str, password: str) -> dict:
response = await self._session.post(
urljoin(
GOOGLEAPIS_URL,
f"{VERIFY_PASSWORD}?key={APP_ID}",
f"{VERIFY_PASSWORD}?key={API_KEY}",
),
data=json.dumps(auth_data),
headers={
Expand All @@ -64,11 +64,7 @@ async def verify_password(self, email: str, password: str) -> dict:
response_json["error"]["code"], response_json["error"]["message"]
)

valid_data = {
"api_token": response_json["localId"],
"access_token": response_json["idToken"],
}
return valid_data
return response_json

async def get_robots(self, access_token: str, api_token: str) -> dict:
"""Get the Garage Robots."""
Expand Down
Loading

0 comments on commit 70af9b2

Please sign in to comment.