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

[Bug] Setup broken #91

Open
b24home opened this issue Feb 26, 2024 · 10 comments
Open

[Bug] Setup broken #91

b24home opened this issue Feb 26, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@b24home
Copy link

b24home commented Feb 26, 2024

Describe the bug
Even after following directions to modify the config.yaml file, I cannot make this work. Installing through HACS leads to an error message that says the UI cannot be used. I’ve instead modified the configuration file, but upon restart, there are still no signs (in the devices nor the integrations section) that things have worked.

@b24home b24home added the bug Something isn't working label Feb 26, 2024
@Jbrown47
Copy link

Having kind of the same issue. But I get no error. Just doesn't show up.

@Waank1
Copy link

Waank1 commented Mar 18, 2024

Having the same problem, getting the following error:

Detected blocking call to putrequest inside the event loop by custom integration 'sengledapi' at custom_components/sengledapi/sengledapi/devices/request.py, line 40: r = requests.post(self._url, headers=self._header, data=self._payload), please report it to the author of the 'sengledapi' custom integration

@Waank1
Copy link

Waank1 commented Apr 5, 2024

Getting following error:

Logger: homeassistant.components.light
Source: components/light/init.py:1325
integration: Light (documentation, issues)
First occurred: 14:13:43 (8 occurrences)
Last logged: 14:13:43

Entity None (<class 'custom_components.sengledapi.light.SengledBulb'>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <LightEntityFeature: 1> and color modes, please report it to the author of the 'sengledapi' custom integration and reference https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation
Entity None (<class 'custom_components.sengledapi.light.SengledBulb'>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <LightEntityFeature: 19> and color modes, please report it to the author of the 'sengledapi' custom integration and reference https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation

@perezjoseph
Copy link

perezjoseph commented Apr 10, 2024

You have to modify class request on request.py

After modifying I was able to get the integration working.

class Request:
def init(self, url, payload, no_return=False):
_LOGGER.info("SengledApi: Sengled Request initializing.")
self._url = url
self._payload = json.dumps(payload)
self._no_return = no_return
self._response = None
self._jsession_id = None

    self._header = {
        "Content-Type": "application/json",
        "Host": "element.cloud.sengled.com:443",
        "Connection": "keep-alive",
    }

async def async_get_response(self, jsession_id):
    self._header = {
        "Content-Type": "application/json",
        "Cookie": f"JSESSIONID={jsession_id}",
        "Connection": "keep-alive",
    }
    
    
    sslcontext = ssl.create_default_context(cafile=certifi.where())

    # Use aiohttp's ClientSession for asynchronous HTTP requests.
    async with aiohttp.ClientSession() as session:
        async with session.post(self._url, headers=self._header, data=self._payload, ssl=sslcontext) as response:
            if response.status == 200:
                data = await response.json()
                return data
            else:
                return None

@perezjoseph
Copy link

"""Sengled Bulb Integration."""

import json
import logging
import ssl

import aiohttp
import certifi
import requests

from .exceptions import SengledApiAccessToken

_LOGGER = logging.getLogger(__name__)

_LOGGER.info("SengledApi: Initializing Request")


class Request:
    def __init__(self, url, payload, no_return=False):
        _LOGGER.info("SengledApi: Sengled Request initializing.")
        self._url = url
        self._payload = json.dumps(payload)
        self._no_return = no_return
        self._response = None
        self._jsession_id = None

        self._header = {
            "Content-Type": "application/json",
            "Host": "element.cloud.sengled.com:443",
            "Connection": "keep-alive",
        }

    async def async_get_response(self, jsession_id):
        self._header = {
            "Content-Type": "application/json",
            "Cookie": f"JSESSIONID={jsession_id}",
            "Connection": "keep-alive",
        }
        
        # It's important to create a new SSL context for secure HTTPS requests.
        sslcontext = ssl.create_default_context(cafile=certifi.where())

        # Use aiohttp's ClientSession for asynchronous HTTP requests.
        async with aiohttp.ClientSession() as session:
            async with session.post(self._url, headers=self._header, data=self._payload, ssl=sslcontext) as response:
                # Make sure to handle potential exceptions and non-JSON responses appropriately.
                if response.status == 200:
                    data = await response.json()
                    return data
                else:
                    # Log an error or handle the response appropriately if not successful.
                    return None

    ########################Login#####################################
    def get_login_response(self):
        _LOGGER.info("SengledApi: Get Login Reponse.")
        r = requests.post(self._url, headers=self._header, data=self._payload)
        data = r.json()
        _LOGGER.debug("SengledApi: Get Login Reponse %s", str(data))
        return data

    async def async_get_login_response(self):
        _LOGGER.info("SengledApi: Get Login Response async.")
        async with aiohttp.ClientSession() as session:
            sslcontext = ssl.create_default_context(cafile=certifi.where())
            async with session.post(
                self._url, headers=self._header, data=self._payload, ssl=sslcontext
            ) as resp:
                data = await resp.json()
                _LOGGER.debug("SengledApi: Get Login Response %s ", str(data))
                return data

    ######################Session Timeout#################################
    def is_session_timeout_response(self, jsession_id):
        _LOGGER.info("SengledApi: Get Session Timeout Response")
        self._header = {
            "Content-Type": "application/json",
            "Cookie": "JSESSIONID={}".format(jsession_id),
            "sid": jsession_id,
            "X-Requested-With": "com.sengled.life2",
        }

        r = requests.post(self._url, headers=self._header, data=self._payload)
        data = r.json()
        _LOGGER.debug("SengledApi: Get Session Timeout Response %s", str(data))
        return data

    async def async_is_session_timeout_response(self, jsession_id):
        _LOGGER.info("SengledApi: Get Session Timeout Response Async")
        self._header = {
            "Content-Type": "application/json",
            "Cookie": "JSESSIONID={}".format(jsession_id),
            "sid": jsession_id,
            "X-Requested-With": "com.sengled.life2",
        }
        async with aiohttp.ClientSession() as session:
            sslcontext = ssl.create_default_context(cafile=certifi.where())
            async with session.post(
                self._url, headers=self._header, data=self._payload, ssl=sslcontext
            ) as resp:
                data = await resp.json()
                _LOGGER.info(
                    "SengledApi: Get Session Timeout Response Async %s", str(data)
                )
                return data

@Ashok-Varma
Copy link

@perezjoseph
Can you submit this as a pull request

@markayres28
Copy link

Anyone able to report whether this should be working OK again now after replacing the \sengledapi\devices\request.py file with the above code from @perezjoseph ?
I did have this working previously until it was broken and tried to fix it using the details provided.
I'm still having problems though.
I'm getting the following error now .

Logger: homeassistant.setup
Source: setup.py:416
First occurred: 18:39:53 (1 occurrences)
Last logged: 18:39:53

Error during setup of component sengledapi
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/sengledapi/init.py", line 54, in async_setup
await sengledapi_account.async_init()
File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 53, in async_init
self._access_token = await self.async_login(
^^^^^^^^^^^^^^^^^^^^^^^
SESSION.username, SESSION.password, SESSION.device_id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 91, in async_login
self.initialize_mqtt()
~~~~~~~~~~~~~~~~~~~~^^
File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 300, in initialize_mqtt
SESSION.mqtt_client.connect(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
SESSION.mqtt_server["host"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
port=SESSION.mqtt_server["port"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
keepalive=30,
^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.13/site-packages/paho/mqtt/client.py", line 1080, in reconnect
sock = WebsocketWrapper(sock, self._host, self._port, self._ssl,
self._websocket_path, self._websocket_extra_headers)
File "/usr/local/lib/python3.13/site-packages/paho/mqtt/client.py", line 3713, in init
self._do_handshake(extra_headers)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/paho/mqtt/client.py", line 3766, in _do_handshake
raise WebsocketConnectionError(
"WebSocket handshake error, connection not upgraded")
paho.mqtt.client.WebsocketConnectionError: WebSocket handshake error, connection not upgraded

Is there some other step or setup that I've missed? Any help would be greatly appreciated. I'd love to get this to work again.

@Waank1
Copy link

Waank1 commented Dec 27, 2024

The integration is still working for me, just throwing errors in the log.

@jeremyheslop
Copy link
Collaborator

jeremyheslop commented Jan 4, 2025

@perezjoseph Can you submit this as a pull request

I took the code, cleaned up some errors, and was able to get my setup working again with this pull request: #93. Hopefully, I did not introduce any regressions. But it is working for my Wi-Fi lights. If someone would like to test it, please get back to everyone. Thanks!

@xevg
Copy link

xevg commented Jan 10, 2025

I just tried to use the sengledapi for the first time, and I am still getting similar errors to above:

2025-01-09 22:20:43.753 INFO (ImportExecutor_0) [custom_components.sengledapi.sengledapi.devices.bulbs.bulb] SengledApi: Initializing Bulbs
2025-01-09 22:20:43.776 INFO (ImportExecutor_0) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Initializing Request
2025-01-09 22:21:14.437 INFO (MainThread) [custom_components.sengledapi] 
    -------------------------------------------------------------------
    Sengled Bulb Home Assistant Integration Created from Config
    Version: v0.2
    This is a custom integration
    If you have any issues with this you need to open an issue here:
    https://github.com/jfarmer08/ha-sengledapi
    -------------------------------------------------------------------
2025-01-09 22:21:14.437 INFO (MainThread) [custom_components.sengledapi] Creating new SengledApi component
2025-01-09 22:21:14.438 INFO (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] Sengled Api initializing.
2025-01-09 22:21:14.439 INFO (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] Sengled Api initializing async.
2025-01-09 22:21:14.441 INFO (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] Sengledapi: Login
2025-01-09 22:21:14.442 INFO (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] SengledApi: Login Request.
2025-01-09 22:21:14.442 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Sengled Request initializing.
2025-01-09 22:21:14.442 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Get Login Response async.
2025-01-09 22:21:18.689 DEBUG (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Get Login Response {'ret': 2, 'msg': '用户名或密码错误', 'customerId': None, 'mobileId': None, 'nick_name': '', 'relative_path': '', 'jsessionId': '', 'ucenterAddr': '', 'appServerAddr': '', 'serAddressess': None, 'privacyPolicyStatus': None} 
2025-01-09 22:21:18.690 DEBUG (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] SengledApi Login {'ret': 2, 'msg': '用户名或密码错误', 'customerId': None, 'mobileId': None, 'nick_name': '', 'relative_path': '', 'jsessionId': '', 'ucenterAddr': '', 'appServerAddr': '', 'serAddressess': None, 'privacyPolicyStatus': None}
2025-01-09 22:21:18.690 INFO (MainThread) [custom_components.sengledapi] SengledApi Connected to Sengled account
2025-01-09 22:21:18.690 DEBUG (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] SengledApi: Get Devices.
2025-01-09 22:21:18.690 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Sengled Request initializing.
2025-01-09 22:21:44.377 ERROR (MainThread) [custom_components.sengledapi.sengledapi.devices.request] Failed to get response, status: 404
2025-01-09 22:21:44.400 ERROR (MainThread) [homeassistant.setup] Error during setup of component sengledapi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/sengledapi/__init__.py", line 64, in async_setup
    sengledapi_devices = await sengledapi_account.async_get_devices()
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 183, in async_get_devices
    for d in data["deviceInfos"]:
             ~~~~^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
2025-01-09 22:21:44.403 INFO (MainThread) [homeassistant.setup] Setup of domain sengledapi took 29.97 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants