Cannot import module for custom light component

Hi Guys,

Since it’s my first post, let me say that HASS is just an awesome project. I recently migrate over from OpenHAB and I already achieved more in one week than with OpenHAB in couple of months. Still - I’m not a python developer, so excuse my noob questions.

I’m trying to develop custom component for great BLEBOX wLightBoxS - wifi enabled LED dimmer. I used this document as an example:

Since this device is http controlled, I need some http library, I usually use urllib. So I created following component, but it’s throwing error during HASS start:

Error:
Oct 03 23:02:41 orangepiplus2e hass[1503]: 2017-10-03 23:02:41 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform blebox_wlightboxs
Oct 03 23:02:41 orangepiplus2e hass[1503]: Traceback (most recent call last):
Oct 03 23:02:41 orangepiplus2e hass[1503]: File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 164, in _async_setup_platform
Oct 03 23:02:41 orangepiplus2e hass[1503]: SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
Oct 03 23:02:41 orangepiplus2e hass[1503]: File “/usr/lib/python3.4/asyncio/tasks.py”, line 372, in wait_for
Oct 03 23:02:41 orangepiplus2e hass[1503]: return fut.result()
Oct 03 23:02:41 orangepiplus2e hass[1503]: File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
Oct 03 23:02:41 orangepiplus2e hass[1503]: raise self._exception
Oct 03 23:02:41 orangepiplus2e hass[1503]: File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
Oct 03 23:02:41 orangepiplus2e hass[1503]: result = self.fn(*self.args, **self.kwargs)
Oct 03 23:02:41 orangepiplus2e hass[1503]: File “/home/homeassistant/.homeassistant/custom_components/light/blebox_wlightboxs.py”, line 33, in setup_platform
Oct 03 23:02:41 orangepiplus2e hass[1503]: if urllib3.urlopen(device).getcode() != 200:
Oct 03 23:02:41 orangepiplus2e hass[1503]: AttributeError: ‘module’ object has no attribute ‘urlopen’

I have no idea how to properly import urllib3

Another question is how to easier debug the code for custom components - right now I need to restart HASS every time I update the code.

Thanks in advance!

I will answer myself: after more reading I think I broke all possible rules in HASS development :wink: Despite that I managed to get this working:

It’s still ugly and I will refactor it, but I just wanted to get some draft before moving forward.

Anyway, I have other problem now. Turning on and off works, but I cannot see any brightness control despite implementing it. Anyone could point me to where I made fundamental mistakes?

So, I was not flagging features properly. I think I solved the problem, now time for refactor and proper implementation of API calls.

Where can I find latest code for BLEBOX wLightBoxS?

Sorry for late reply, forum was in read only mode.

The code is not published anywhere, I need to spend some time and polish it.

Is any chance to implement it to HA official and share on page HA full manual to config it ? I also think about blebox shutter.

Here are all documentation blebox API http://technical.blebox.eu/

I don’t really have time to polish it now, but it works quite well