jfarmer08 / ha-sengledapi

Home Assistant Integration for Sengled Bulbs. This is a custom component to allow control of Sengled Bulbs in Homeassistant using the unofficial Sengled API. Please note this mimics the Sengled app and therefore Sengled may cut off access at anytime.
Apache License 2.0
104 stars 34 forks source link

[Bug] Setup broken #91

Open b24home opened 6 months ago

b24home commented 6 months ago

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.

Jbrown47 commented 6 months ago

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

Waank1 commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago
"""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