Giter Club home page Giter Club logo

python-hass-client's Introduction

hass-client

Very basic client for connecting to Home Assistant over websockets and REST.

python-hass-client's People

Contributors

marcelveldt avatar dependabot[bot] avatar lmagyar avatar

Stargazers

Chrissi^ (Chris Fiege) avatar flako avatar Sebastiano Zuddas avatar  avatar Johannes avatar Kevin Sieck avatar  avatar Tobias Wasner avatar Tim avatar Dr. Magnus Christ avatar Luis Felipe Llamas Luaces avatar Edwin avatar

Watchers

 avatar James Cloos avatar  avatar

python-hass-client's Issues

Cannot import name "HomeAssistant" from hass_client.

We tried running the file unchanged after installing the packages and running the setup.py file, and got the error presented in the title.

image

I see this is 2 years old, has there been changes/updates that makes this solution obsolete?

This is in the test.py file...

Seems to be completely broken, example code doesn't work

The example code (refactored):

def log_events(event: Event) -> None:
    print(event)

async def main():
    logging.basicConfig(level=logging.DEBUG)
    async with ClientSession() as session:
        async with HomeAssistantClient("wss://xxx/api/websocket", get_secret("xxx"), session) as client:
            await client.subscribe_events(log_events)
            await client.start_listening()

Log:

DEBUG:hass_client:Connecting to Home Assistant Websocket API on wss://xxx/api/websocket
INFO:hass_client:Connected to Home Assistant xxx (version 2024.6.2)
DEBUG:hass_client:Publishing message:
{'event_type': '*', 'id': 2, 'type': 'subscribe_events'}
### no messages at all ###
### CTRL-C ###
DEBUG:hass_client:Closing client connection

While manual connection works flawlessly:

async def main():
    async with ClientSession() as session:
        socket = await session.ws_connect("wss://xxx/api/websocket", heartbeat=55, max_msg_size=1024 * 1024)

        version_msg = await socket.receive_json()
        version = version_msg["ha_version"]
        print(version)

        auth_command = {
            "type": "auth",
            "access_token": get_secret("xxx"),
        }
        await socket.send_json(auth_command)

        auth_result = await socket.receive_json()
        if auth_result["type"] != "auth_ok":
            raise AuthenticationError(auth_result.get("message", "Authentication failed"))

        await socket.send_json({'id': 1, 'type': 'subscribe_events', 'event_type': '*'})    
        while True:
            message = await socket.receive_json()
            if message is None:
                break
            print(message)

More detail in README

Hello, I really like what you've made here. It would be great to get some more details on using this via the README.

Can't connect to Home-Assistant with self-signed certificates

Hi,

I'm trying to add Home-Assistant as a player provider but if fails because of a self-signed certificate.
2024-05-31 23:17:46.925 ERROR (MainThread) [music_assistant.webserver] Error handling message: config/providers/get_entries: Cannot connect to host xxx.xxx.xxx:8123 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)')]

Looks like aiohttp need to have the flag ssl=false which could be added as an option on the UI.
Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.