Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local API support to Overkiz integration (Somfy TaHoma Developer Mode) #71644

Merged
merged 90 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
906d00f
Add initial config flow implementation
iMicknl Apr 11, 2022
4a1bd2b
Add initial config flow implementation
iMicknl Apr 11, 2022
3b83a5d
Add todos
iMicknl Apr 11, 2022
1e0a3f1
Bugfixes
iMicknl Apr 11, 2022
04bf175
Add first zeroconf code
iMicknl Apr 11, 2022
e0c96af
Fixes for new firmware
iMicknl May 10, 2022
432a78d
Bugfixes for local integration
iMicknl May 10, 2022
e1e10b3
Delete local token
iMicknl May 10, 2022
b3d5c01
Fix diagnostics
iMicknl Jun 26, 2022
ba71c6b
Update translations and improve code
iMicknl Jun 26, 2022
002fbe3
Update translations and improve code
iMicknl Jun 26, 2022
3c1f54a
Add local integration updates
iMicknl Aug 12, 2022
23b486f
Add local integration updates
iMicknl Aug 12, 2022
dbe4fc2
Small tweaks
iMicknl Sep 4, 2022
b52f2f1
Add comments
iMicknl Oct 16, 2022
fa0cc81
Bugfix
iMicknl Nov 5, 2022
5ce114e
Small code improvements
iMicknl Nov 6, 2022
0a58f7b
Small code improvements
iMicknl Nov 6, 2022
aedecf9
Small code improvements
iMicknl Nov 6, 2022
d416304
Small code improvements
iMicknl Nov 6, 2022
1bab6d7
Small code improvements
iMicknl Nov 6, 2022
e0d64e3
Small code improvements
iMicknl Nov 6, 2022
5d5feee
Bugfixes
iMicknl Nov 6, 2022
a1edc47
Small code improvements
iMicknl Nov 6, 2022
be74fd4
Small code improvements
iMicknl Nov 6, 2022
3531108
Change Config Flow (breaking change)
iMicknl Jun 23, 2023
4f92268
Remove token when integration is unloaded
iMicknl Jun 23, 2023
2547c63
Remove print
iMicknl Jun 23, 2023
e694c7f
Simplify
iMicknl Jun 23, 2023
1211403
Bugfixes
iMicknl Jun 23, 2023
0606712
Improve configflow
iMicknl Jun 23, 2023
1aa8eb8
Clean up unnecessary things
iMicknl Jun 25, 2023
380e585
Catch nosuchtoken exception
iMicknl Jun 25, 2023
fff5817
Add migration for Config Flow
iMicknl Jun 26, 2023
1af1fc3
Add version 2 migration
iMicknl Jun 26, 2023
30cbe7c
Revert change in Config Flow
iMicknl Jun 26, 2023
38e46b4
Fix api type
iMicknl Jun 26, 2023
81b56f0
Update strings
iMicknl Jun 26, 2023
883a962
Improve migrate entry
iMicknl Jun 26, 2023
0e73d82
Implement changes
iMicknl Jun 27, 2023
5be65a5
add more comments
iMicknl Jun 27, 2023
d20716f
Extend diagnostics
iMicknl Jun 27, 2023
4e7d836
Ruff fixes
iMicknl Jun 27, 2023
8d82d83
Clean up code
iMicknl Jun 27, 2023
c3044fa
Bugfixes
iMicknl Jun 28, 2023
a858478
Set gateway id
iMicknl Jun 28, 2023
a011a0c
Start writing tests
iMicknl Jun 29, 2023
27d54b8
Add first local test
iMicknl Jun 30, 2023
a18f8d0
Code coverage to 64%
iMicknl Jun 30, 2023
6490316
Fixes
iMicknl Jun 30, 2023
1552811
Remove local token on remove entry
iMicknl Jul 9, 2023
1a9f115
Add debug logging + change manifest
iMicknl Jul 9, 2023
7fa0072
Add developer mode check
iMicknl Jul 27, 2023
d4a7d63
Fix not_such_token issue
iMicknl Jul 27, 2023
033c9fa
Small text changes
iMicknl Jul 27, 2023
d985f8c
Bugfix
iMicknl Jul 27, 2023
57017f1
Fix tests
iMicknl Aug 2, 2023
77f67a6
Address feedback
iMicknl Aug 6, 2023
1f1fe91
DRY
iMicknl Aug 6, 2023
bfc2de6
Test coverage to 77%
iMicknl Aug 6, 2023
09d130f
Coverage to 78%
iMicknl Aug 6, 2023
0a7b6d1
Remove token removal by UUID
iMicknl Aug 6, 2023
5114733
Add better retry methods
iMicknl Aug 6, 2023
ad32e88
Clean up
iMicknl Aug 6, 2023
9d024b2
Remove old data
iMicknl Aug 6, 2023
6c7b60e
87% coverage
iMicknl Aug 6, 2023
6a08fed
90% code coverage
iMicknl Aug 6, 2023
a465524
100% code coverage
iMicknl Aug 6, 2023
61d6356
Use patch.multiple
iMicknl Aug 6, 2023
90b531a
Improve tests
iMicknl Aug 6, 2023
9454542
Apply pre-commit after rebase
iMicknl Oct 8, 2023
bf5aea8
Fix breaking changes in ZeroconfServiceInfo
iMicknl Oct 8, 2023
f26a909
Add verify_ssl
iMicknl Nov 6, 2023
8dcf4a9
Fix test import
iMicknl Nov 6, 2023
819807e
Fix tests
iMicknl Nov 6, 2023
e2a11d3
Catch SSL verify failed
iMicknl Nov 6, 2023
2dbba6a
Revert hub to server rename
iMicknl Nov 6, 2023
6de359a
Move Config Flow version back to 1
iMicknl Nov 6, 2023
6ad736b
Add diagnostics tests
iMicknl Nov 7, 2023
ece7bd5
Fix tests
iMicknl Nov 7, 2023
d2554a2
Fix strings
iMicknl Nov 7, 2023
25ff309
Implement feedback
iMicknl Nov 9, 2023
26e4bbc
Add debug logging for local connection errors
iMicknl Nov 9, 2023
878dbeb
Simplify Config Flow and fix tests
iMicknl Nov 11, 2023
2213e17
Simplify Config Flow
iMicknl Nov 11, 2023
a8110f9
Fix verify_ssl
iMicknl Nov 11, 2023
8323660
Fix rebase mistake
iMicknl Nov 12, 2023
ed5f9ba
Address feedback
iMicknl Nov 21, 2023
828cdc1
Apply suggestions from code review
emontnemery Nov 22, 2023
82e2e4c
Update tests/components/overkiz/test_config_flow.py
emontnemery Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 59 additions & 11 deletions homeassistant/components/overkiz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@
from aiohttp import ClientError
from pyoverkiz.client import OverkizClient
from pyoverkiz.const import SUPPORTED_SERVERS
from pyoverkiz.enums import OverkizState, UIClass, UIWidget
from pyoverkiz.enums import APIType, OverkizState, UIClass, UIWidget
from pyoverkiz.exceptions import (
BadCredentialsException,
MaintenanceException,
NotSuchTokenException,
TooManyRequestsException,
)
from pyoverkiz.models import Device, Scenario, Setup
from pyoverkiz.models import Device, OverkizServer, Scenario, Setup
from pyoverkiz.utils import generate_local_server

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_TOKEN,
CONF_USERNAME,
CONF_VERIFY_SSL,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.aiohttp_client import async_create_clientsession

from .const import (
CONF_API_TYPE,
CONF_HUB,
DOMAIN,
LOGGER,
Expand All @@ -48,15 +57,26 @@ class HomeAssistantOverkizData:

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Overkiz from a config entry."""
username = entry.data[CONF_USERNAME]
password = entry.data[CONF_PASSWORD]
server = SUPPORTED_SERVERS[entry.data[CONF_HUB]]
client: OverkizClient | None = None
api_type = entry.data.get(CONF_API_TYPE, APIType.CLOUD)

# Local API
if api_type == APIType.LOCAL:
client = create_local_client(
hass,
host=entry.data[CONF_HOST],
token=entry.data[CONF_TOKEN],
verify_ssl=entry.data[CONF_VERIFY_SSL],
)

# To allow users with multiple accounts/hubs, we create a new session so they have separate cookies
session = async_create_clientsession(hass)
client = OverkizClient(
username=username, password=password, session=session, server=server
)
# Overkiz Cloud API
else:
client = create_cloud_client(
hass,
username=entry.data[CONF_USERNAME],
password=entry.data[CONF_PASSWORD],
server=SUPPORTED_SERVERS[entry.data[CONF_HUB]],
)

await _async_migrate_entries(hass, entry)

Expand Down Expand Up @@ -211,3 +231,31 @@ def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None:
await er.async_migrate_entries(hass, config_entry.entry_id, update_unique_id)

return True


def create_local_client(
hass: HomeAssistant, host: str, token: str, verify_ssl: bool
) -> OverkizClient:
"""Create Overkiz local client."""
session = async_create_clientsession(hass, verify_ssl=verify_ssl)

return OverkizClient(
username="",
password="",
token=token,
session=session,
server=generate_local_server(host=host),
verify_ssl=verify_ssl,
)


def create_cloud_client(
hass: HomeAssistant, username: str, password: str, server: OverkizServer
) -> OverkizClient:
"""Create Overkiz cloud client."""
# To allow users with multiple accounts/hubs, we create a new session so they have separate cookies
session = async_create_clientsession(hass)

return OverkizClient(
username=username, password=password, session=session, server=server
)