Core: TPLINK - platform BULB loading error

Created on 23 Mar 2019  Â·  7Comments  Â·  Source: home-assistant/core

Home Assistant release with the issue:

0.90.0

Last working Home Assistant release (if known):
0.88.0

Operating environment (Hass.io/Docker/Windows/etc.):

unraid docker
Component/platform:

tplink:
Light:

Description of problem:

  1. ignores all -host definitions (no error in log)
    2.discovery: true option -> NO BULBS are discovered, DOES FIND switches and plugs (TP-Link Smart Home is configured and shows only switches and plugs )
    error:
Log Details (ERROR)
Fri Mar 22 2019 22:54:47 GMT-0400 (Eastern Daylight Time)
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 257, in _async_add_entity
    if entity.unique_id is not None:
  File "/usr/src/app/homeassistant/components/tplink/light.py", line 82, in unique_id
    return self._sysinfo["mac"]
TypeError: 'NoneType' object is not subscriptable

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

logger:
  default: error  # error, critical, fatal, info
  logs:
    homeassistant.core: critical
    components.light.tplink: debug
    components.pyHS100: debug

tplink:
  discovery: true
  light:
    - host: 192.168.200.83
    - host: 192.168.200.84
    - host: 192.168.200.124
  switch:
    - host: 192.168.200.81
    - host: 192.168.200.82
    - host: 192.168.200.86

Traceback (if applicable):


Additional information:

light tplink

All 7 comments

still getting same error on Pi and Unraid Homeassistant version 0.90.1

So the most likely explanation is that for some reason the unique_id gets called before the update() has fetched the device information. More information/logs is neede in order to find out why this happens. Could the bulb problems be related to https://github.com/home-assistant/home-assistant/issues/20994 ?

I've been able to reproduce this issue. Simply configure a light that who's power switched off.

tplink:
  discovery: false
  light:
    - host: '192.168.1.255'

You'll get detailed log output like this:

--- Logging error ---
Traceback (most recent call last):
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 117, in _query_helper
    request=request,
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/protocol.py", line 47, in query
    sock = socket.create_connection((host, port), timeout)
  File "/usr/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/usr/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/colorlog/colorlog.py", line 119, in format
    message = super(ColoredFormatter, self).format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 561, in __repr__
    is_on = self.is_on
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 296, in is_on
    return bool(self.state == self.BULB_STATE_ON)
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 249, in state
    light_state = self.get_light_state()
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 107, in get_light_state
    "get_light_state")
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 120, in _query_helper
    raise SmartDeviceException('Communication error') from ex
pyHS100.smartdevice.SmartDeviceException: Communication error
Call stack:
  File "/home/myuser/Documents/git/home-assistant/venv/bin/hass", line 11, in <module>
    load_entry_point('homeassistant', 'console_scripts', 'hass')()
  File "/home/myuser/Documents/git/home-assistant/homeassistant/__main__.py", line 389, in main
    exit_code = asyncio_run(setup_and_run_hass(config_dir, args))
  File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
    self._run_once()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
    handle._run()
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/setup.py", line 177, in _async_setup_component
    await entry.async_setup(hass, integration=integration)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/config_entries.py", line 309, in async_setup
    hass, self)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/components/tplink/__init__.py", line 130, in async_setup_entry
    _LOGGER.debug("Got %s lights: %s", len(lights), lights)
Unable to print the message and arguments - possible formatting error.
Use the traceback above to help find the error.
--- Logging error ---
Traceback (most recent call last):
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 117, in _query_helper
    request=request,
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/protocol.py", line 47, in query
    sock = socket.create_connection((host, port), timeout)
  File "/usr/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/usr/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 561, in __repr__
    is_on = self.is_on
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 296, in is_on
    return bool(self.state == self.BULB_STATE_ON)
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 249, in state
    light_state = self.get_light_state()
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 107, in get_light_state
    "get_light_state")
  File "/home/myuser/Documents/git/home-assistant/venv/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 120, in _query_helper
    raise SmartDeviceException('Communication error') from ex
pyHS100.smartdevice.SmartDeviceException: Communication error
Call stack:
  File "/home/myuser/Documents/git/home-assistant/venv/bin/hass", line 11, in <module>
    load_entry_point('homeassistant', 'console_scripts', 'hass')()
  File "/home/myuser/Documents/git/home-assistant/homeassistant/__main__.py", line 389, in main
    exit_code = asyncio_run(setup_and_run_hass(config_dir, args))
  File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
    self._run_once()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
    handle._run()
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/setup.py", line 177, in _async_setup_component
    await entry.async_setup(hass, integration=integration)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/config_entries.py", line 309, in async_setup
    hass, self)
  File "/home/myuser/Documents/git/home-assistant/homeassistant/components/tplink/__init__.py", line 130, in async_setup_entry
    _LOGGER.debug("Got %s lights: %s", len(lights), lights)
Unable to print the message and arguments - possible formatting error.
Use the traceback above to help find the error.

Ah, now I understand. I'll the problem description I wrote in discord yesterday below, I hope someone can chime in how this should be handled properly:

.. I'd need some feedback from the @home-assistant/core ; the main complaint I'm seeing is the errors caused by devices being offline. but as the detection on what is going to be initialized is already made on the component level, I'm unsure how to handle that

previous system worked by the chance that the raising of PlatformNotReady was enough to make homeassistant to retry the setup, but how should I handle that when the initial whatever_setup is being called by the component, and not on a single devices but on all of supported ones?

so this happens when the user is manually configuring the ip addresses of these devices, and they are not available during the startup. the reason why it worked before is that each platform instance was initialized separately per entity, and if the device was not available, PlatformNotReady was raised and homeassistant tried to initialize it again later on. my point is, I don't know how I can fix the situation :/

Since v .89, after two more releases, TP-Link entities are not recognized by HA via tplink: domain.

.log in filled with errors. Looks like TP-link is abandoned by HA!

I have tried and wasted lot of time to find work around, no luck.

Most discussions on this issue is on procedural things related to HA and forums!

In two years of HA use and tons of integrations, I have never seen a revision like v.90.x that require me to replace devices which will COST $.

B Patel

From: Teemu R. notifications@github.com
Sent: Thursday, May 2, 2019 7:22 PM
To: home-assistant/home-assistant home-assistant@noreply.github.com
Cc: Balvant Patel softdev@balvantpatel.com; Author author@noreply.github.com
Subject: Re: [home-assistant/home-assistant] TPLINK - platform BULB loading error (#22313)

Ah, now I understand. The problem description I wrote in discord the other day. I hope someone can chime in how this should be handled properly:

.. I'd need some feedback from the @home-assistant/core https://github.com/orgs/home-assistant/teams/core ; the main complaint I'm seeing is the errors caused by devices being offline. but as the detection on what is going to be initialized is already made on the component level, I'm unsure how to handle that

previous system worked by the chance that the raising of PlatformNotReady was enough to make homeassistant to retry the setup, but how should I handle that when the initial whatever_setup is being called by the component, and not on a single devices but on all of supported ones?

so this happens when the user is manually configuring the ip addresses of these devices, and they are not available during the startup. the reason why it worked before is that each platform instance was initialized separately per entity, and if the device was not available, PlatformNotReady was raised and homeassistant tried to initialize it again later on. my point is, I don't know how I can fix the situation :/

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant/issues/22313#issuecomment-488866315 , or mute the thread https://github.com/notifications/unsubscribe-auth/AIJVSM73KNOIXNLBGSJLAYLPTNZRXANCNFSM4HASXE3Q . https://github.com/notifications/beacon/AIJVSM7EUG65IL4FTRYSPZDPTNZRXA5CNFSM4HASXE32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODURYECY.gif

Like I explained in my previous message, there are issues when the devices are not available during the configuration / restart phase, and I'm terribly sorry about that. Maybe some of those can be easily fixed somehow, but I don't know how.

I actually also have some other responsibilities besides maintaining the integration (I just moved temporarily to another continent, so I don't have access to my switch or my setup), so it will take some time until I'll be able to work on this. I did just order some bulbs in the hopes that I'll find some time soon enough to improve the situation, but until then, I hope someone else will chime in and explain what is the best approach to fix this.

Thanks for your appreciative messages though, it's always great to hear that all the effort I have put contributing to this project (and the backend library pyhs100 used by this integration) hasn't gone completely unnoticed!

@rytilahti I went ahead and fixed the issues described in this ticket. The pull request needs your review though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

coolriku picture coolriku  Â·  3Comments

aweb-01 picture aweb-01  Â·  3Comments

TheZoker picture TheZoker  Â·  3Comments

Elmardus picture Elmardus  Â·  3Comments

neonandu picture neonandu  Â·  3Comments