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 - Addon and lights don't load #82

Open
hocahoon opened this issue Dec 15, 2022 · 15 comments
Open

Bug - Addon and lights don't load #82

hocahoon opened this issue Dec 15, 2022 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@hocahoon
Copy link

Describe the bug
Addon has been running great, thanks for making this, it's a lifesaver. But now the light don't load and I get errors.

To Reproduce
Steps to reproduce the behavior:
HACs or manual install of sengled api

Expected behavior
To work like it always has

System configuration
RPi
Home Assistant 2022.8.6
Supervisor 2022.11.2
Operating System 8.5
Frontend 20220802.0 - latest

Latest Master

configuration.yaml
sengledapi:
username:
password:
country: us
wifi: true

home-assistant.log

@hocahoon hocahoon added the bug Something isn't working label Dec 15, 2022
@hocahoon
Copy link
Author

So I just booted up a new HomeAssistant VM, loaded nothing but this addon and it worked with the same username and password that i'm trying to use on my main build.

@jfarmer08
Copy link
Owner

Do you have any logs.

@hocahoon
Copy link
Author

Log Details (ERROR)
Logger: homeassistant.setup
Source: util/async_.py:168
First occurred: 6:18:32 PM (1 occurrences)
Last logged: 6:18:32 PM

Error during setup of component sengledapi
Traceback (most recent call last):
File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 253, in async_do_request
return await Request(url, payload).async_get_response(jsessionId)
File "/config/custom_components/sengledapi/sengledapi/devices/request.py", line 57, in async_get_response
data = await resp.json()
File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1103, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://element.cloud.sengled.com/zigbee/device/getDeviceDetails.json')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 235, 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 182, in async_get_devices
data = await self.async_do_request(url, payload, SESSION.jsession_id)
File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 255, in async_do_request
return Request(url, payload).get_response(jsessionId)
File "/config/custom_components/sengledapi/sengledapi/devices/request.py", line 40, in get_response
r = requests.post(self._url, headers=self._header, data=self._payload)
File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1293, in send_request
self.putrequest(method, url, **skips)
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 219, in putrequest
return HTTPConnection.putrequest(self, method, url, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 180, in protected_loop_func
check_loop(func, strict=strict)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 168, in check_loop
raise RuntimeError(
RuntimeError: Blocking calls must be done in the executor or a separate thread; Use await hass.async_add_executor_job(); at custom_components/sengledapi/sengledapi/devices/request.py, line 40: r = requests.post(self._url, headers=self._header, data=self._payload)

@hocahoon
Copy link
Author

Logger: homeassistant.util.async_
Source: util/async_.py:180
First occurred: 6:18:32 PM (1 occurrences)
Last logged: 6:18:32 PM

Detected blocking call to putrequest inside the event loop. This is causing stability issues. Please report issue to the custom integration author for sengledapi doing blocking calls at custom_components/sengledapi/sengledapi/devices/request.py, line 40: r = requests.post(self._url, headers=self._header, data=self._payload)

@hocahoon
Copy link
Author

Let me know if those aren't the right ones, thank you very much for the response and help.

@jfarmer08
Copy link
Owner

So it's might take time for me look at this. I don't use home assistant anymore. So in the past when I have seen this issue it with this call below. And normally it because of the username and password. The blocking part is because we are not call async get response, but could be because we are not getting the correct response from the do request. I will look into this more.

-`def get_response(self, jsession_id):
self._header = {
"Content-Type": "application/json",
"Cookie": "JSESSIONID={}".format(jsession_id),
"Connection": "keep-alive",
}

    r = requests.post(self._url, headers=self._header, data=self._payload)
    data = r.json()
    return data

async def async_get_response(self, jsession_id):
    self._header = {
        "Content-Type": "application/json",
        "Cookie": "JSESSIONID={}".format(jsession_id),
        "Host": "element.cloud.sengled.com:443",
        "Connection": "keep-alive",
    } `

` #######################Do request#######################################################
async def async_do_request(self, url, payload, jsessionId):
try:
return await Request(url, payload).async_get_response(jsessionId)
except:
return Request(url, payload).get_response(jsessionId)

###################################Login Request only###############################
async def async_do_login_request(self, url, payload):
    _LOGGER.info("SengledApi: Login Request.")
    try:
        return await Request(url, payload).async_get_login_response()
    except:
        return Request(url, payload).get_login_response() `

@hocahoon
Copy link
Author

I looked through other issues and saw that your recommendation was to check the user name and password. I've reset the password a few times already with no luck. That's why I tried the addon in a fresh VM and it worked as expected.

What do you use now if you don't use HA if you don't mind me asking?

@jfarmer08
Copy link
Owner

I have moved away from Sengled and I am using wyze. For the platform I am using Homebridge. I found that I don't need all the other features that home assistant has to offer.

@wmhartl
Copy link

wmhartl commented Dec 19, 2022

Seeing this also. Let me know if you come up with a fix - more than happy to test it.

@KevinBodwell
Copy link

I was getting a similar error today. Two things I did was added trust_env=true to the ClientSession, which got me past the initial error. Then got a another error with more info:

2022-12-26 16:08:17.143 INFO (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] SengledApi: Login Request. 2022-12-26 16:08:17.143 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Sengled Request initializing. 2022-12-26 16:08:17.144 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Get Login Response async. 2022-12-26 16:08:26.798 DEBUG (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Get Login Response {'ret': 0, 'msg': 'success', 'customerId': 831948, 'mobileId': 0, 'nick_name': '<redacted>', 'relative_path': None, 'jsessionId': '<redacted>', 'ucenterAddr': '', 'appServerAddr': '', 'serAddressess': None, 'privacyPolicyStatus': 1} 2022-12-26 16:08:26.801 DEBUG (MainThread) [custom_components.sengledapi.sengledapi.sengledapi] SengledApi Login {'ret': 0, 'msg': 'success', 'customerId': 831948, 'mobileId': 0, 'nick_name': '<redacted>', 'relative_path': None, 'jsessionId': '<redacted>', 'ucenterAddr': '', 'appServerAddr': '', 'serAddressess': None, 'privacyPolicyStatus': 1} 2022-12-26 16:08:26.801 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Sengled Request initializing. 2022-12-26 16:08:27.150 WARNING (MainThread) [homeassistant.setup] Setup of sengledapi is taking over 10 seconds. 2022-12-26 16:08:31.842 INFO (MainThread) [custom_components.sengledapi.sengledapi.devices.request] SengledApi: Sengled Request initializing. 2022-12-26 16:08:36.853 ERROR (MainThread) [homeassistant.setup] Error during setup of component sengledapi File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 253, in async_do_request File "/config/custom_components/sengledapi/sengledapi/devices/request.py", line 54, in async_get_response aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host life2.cloud.sengled.com:443 ssl:<ssl.SSLContext object at 0xa4ac3808> [Try again] urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='life2.cloud.sengled.com', port=443): Max retries exceeded with url: /life2/server/getServerInfo.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x9de85df0>: Failed to establish a new connection: [Errno -3] Try again')) 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 File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 88, in async_login File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 135, in async_get_server_info File "/config/custom_components/sengledapi/sengledapi/sengledapi.py", line 255, in async_do_request File "/config/custom_components/sengledapi/sengledapi/devices/request.py", line 40, in get_response requests.exceptions.ConnectionError: HTTPSConnectionPool(host='life2.cloud.sengled.com', port=443): Max retries exceeded with url: /life2/server/getServerInfo.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x9de85df0>:

From this I was looking back through the recent closed issues and stumbled on #77 talking about hundreds of DNS requests. As I too run pihole I checked and sure enough had the same issue with hundreds of requests. I tried the comment in there are adjusted SCAN_INTERVAL to 30, and restarted and all is working. I think we may be getting blocked by a rate limiter.

@hocahoon
Copy link
Author

@KevinBodwell That's great news, thanks for sharing a fix man!

Can you help with where you put trust_env=true? I'm stuck on what file to modify and where to place it in the code.

@hocahoon
Copy link
Author

hocahoon commented Dec 27, 2022

So I've got mine working again, i did three things simultaneously so unsure which one did the trick. I changed the password again in the IOS app, and I changed the dns on the router to Quad9 instead of Adguard.

I also capitalized the country in the .yaml config

I suspect the Adguard was the trick, but it's working at the moment.

@hocahoon
Copy link
Author

Wanted to share for anyone looking for a fix now or in the future, I was able to link Sengled with Smarthings, with no Smarthings hub and pull them into Homeassistant flawlessly.

@Tweakalot
Copy link

How did you link via SmartThings? Sengled hub is not listed.

@hocahoon
Copy link
Author

hocahoon commented Apr 5, 2023

How did you link via SmartThings? Sengled hub is not listed.

I linked it via the smartthings app on my phone. I went to add, device, by brand.
A8FD309C-53F5-4EB2-9004-E01AD012DCAA

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

5 participants