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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local support for Somfy Developer Mode #441

Merged
merged 13 commits into from
Apr 11, 2022
Merged

Conversation

iMicknl
Copy link
Owner

@iMicknl iMicknl commented Apr 4, 2022

import asyncio
import time
import aiohttp

from pyoverkiz.client import OverkizClient
from pyoverkiz.const import SUPPORTED_SERVERS, OverkizServer

USERNAME = ""
PASSWORD = ""
LOCAL_GATEWAY = "gateway-1234-4567-8901.local"


async def main() -> None:

    token = ""

    async with OverkizClient(
        username=USERNAME, password=PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]
    ) as client:

        await client.login()
        gateways = await client.get_gateways()

        for gateway in gateways:
            # Generate tokens
            token = await client.generate_local_token(gateway.id)
            print(token)
            uuid = await client.activate_local_token(gateway_id=gateway.id, token=token, label="Home Assistant/local-dev")

    # # List all tokens
    # tokens = await client.get_local_tokens(gateway.id)

    # # Delete tokens
    # for token in tokens:
    #     print(token)
    #     print(await client.delete_local_token(gateway.id, token.uuid))

    # Local Connection
    session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False))

    async with OverkizClient(
        username="", password="", token=token, session=session, server=OverkizServer(
            name="Somfy TaHoma (local)",
            endpoint=f"https://{LOCAL_GATEWAY}:8443/enduser-mobile-web/1/enduserAPI/",
            manufacturer="Somfy",
            configuration_url=None,
        )
    ) as client:
        # print(await client.get_diagnostic_data())
        await client.login()

        print(await client.get_api_version())

        setup = await client.get_setup()
        print(setup)

        # devices = await client.get_devices()
        # print(devices)

        # for device in devices:
        #     print(f"{device.label} ({device.id}) - {device.controllable_name}")
        #     print(f"{device.widget} - {device.ui_class}")

        # while True:
        #     events = await client.fetch_events()
        #     print(events)

        #     time.sleep(2)

asyncio.run(main())

@iMicknl iMicknl marked this pull request as draft April 4, 2022 16:22
@iMicknl iMicknl changed the title Add local support (models + login) for jailbreaked Connexoon Add local support (models + login) for Somfy Developer Mode Apr 7, 2022
@iMicknl iMicknl changed the title Add local support (models + login) for Somfy Developer Mode Add local support for Somfy Developer Mode Apr 7, 2022
@iMicknl iMicknl force-pushed the feature/add_local_login branch from af0b069 to 562d327 Compare April 7, 2022 14:17
cafile=os.path.dirname(os.path.realpath(__file__))
+ "/overkiz-root-ca-2048.crt"
)
self._ssl_context = None
Copy link
Owner Author

@iMicknl iMicknl Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSL check removed for now. We can just pass a session that does not verify SSL.

pyoverkiz/client.py Outdated Show resolved Hide resolved
@iMicknl iMicknl marked this pull request as ready for review April 11, 2022 09:40
@iMicknl iMicknl force-pushed the feature/add_local_login branch from aef0464 to 3c3f24a Compare April 11, 2022 10:40
@@ -122,6 +126,10 @@ def __init__(

self.session = session if session else ClientSession()

if "/enduser-mobile-web/1/enduserAPI/" in server.endpoint:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to add a property named for instance. support_local. WDYT?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was in doubt about this one as well... In the end I would love to see something like this (#321), where we define the auth mechanism in the OverkizServer definition.

Eventually that would be even better, since we can than easily pick any authentication method, and we don't need an extra property just for local.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it in cfa2abc, would that be ok for now? @tetienne

@iMicknl iMicknl merged commit 499a28a into main Apr 11, 2022
@iMicknl iMicknl deleted the feature/add_local_login branch April 11, 2022 12:58
tetienne pushed a commit that referenced this pull request Feb 14, 2023
* Add local support to models

* Add local event tests

* Fix local event listener

* Add local API support

* Add first start to verify local cert

* Implement all local endpoints

* Local fixesak

* Add extra test

* Add Unknown Object exception

* Bugfix

* Remove SSL check for now

* Add AccessDeniedToGatewayException

* Simplify local check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants