home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.02k stars 29.67k forks source link

LaMetric hasslemetricmanager NoneType Error #8829

Closed msenebald closed 6 years ago

msenebald commented 7 years ago

Home Assistant release (hass --version): 0.50.2

Python release (python3 --version): python 3.6.2

Component/platform: LaMetric

Description of problem: following instruction of docu and with test data from: #8230 calling the lametric notify service raises the error below.

Expected: hello world example should send message to lametric device.

Problem-relevant configuration.yaml entries and steps to reproduce:

lametric:
  client_id: xxxxxxx
  client_secret: xxxxxx

notify:
  name: lametric1
  platform: lametric
  display_time: 20
  icon: i555

Traceback (if applicable):

2017-08-05 01:19:31 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=notify, service=lametric1, service_data=message=Test, data=icon=i555, target=['My LaMetric'], service_call_id=139878223764560-4>
2017-08-05 01:19:31 DEBUG (SyncWorker_12) [homeassistant.components.notify.lametric] Targets/Data: ['My LaMetric']/{'icon': 'i555'}
2017-08-05 01:19:31 DEBUG (SyncWorker_12) [homeassistant.components.notify.lametric] Icon/Message/Duration: i555, Test, 20000
2017-08-05 01:19:31 DEBUG (SyncWorker_12) [homeassistant.components.notify.lametric] [<lmnotify.models.SimpleFrame object at 0x7f37bc696048>]
2017-08-05 01:19:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 182, in _step
    result = coro.throw(exc)
  File "/usr/src/app/homeassistant/core.py", line 1025, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/src/app/homeassistant/components/notify/__init__.py", line 138, in async_notify_message
    yield from notify_service.async_send_message(**kwargs)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/notify/lametric.py", line 85, in send_message
    lmn = self.hasslametricmanager.manager()
AttributeError: 'NoneType' object has no attribute 'manager'

Additional info: hass runs inside the latest docker container and to do calls outside goes through a proxy. (http_proxy & https_proxy env set)

to make sure connectivity for this works i check within the container, used the same libraries and same env variables directly in a python console

i did the following to verify:

from lmnotify import LaMetricManager, Model, SimpleFrame
CLIENT_ID = "xxxxxxxx"
CLIENT_SECRET = "xxx"
lmn = LaMetricManager(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
devices = lmn.get_devices()
devices
# output: [{'id': 17438, 'name': 'My LaMetric', 'state': 'configured', 'serial_number': 'SA17060154xxxxxxxxxxxxx', 'api_key': 'xxxxxxxxxxxxxx', 'ipv4_internal': 'xxxxxx, 'mac': 'xxxxxxxx', 'wifi_ssid': 'xxxx', 'created_at': '2017-06-20T17:44:18+03:00', 'updated_at': '2017-08-04T18:35:53+03:00'}]
lmn.set_device(devices[0])
sf = SimpleFrame("i555", "Hello World!")
model = Model(frames=[sf])
lmn.send_notification(model)
# output {'success': {'id': '5'}}

i dug a bit in the code but didn't figure out why this object is not available at that stage.

cr0 commented 7 years ago

Same here, hass version is 0.51.2 and python is 3.5.3. Everything runs in an ubuntu lxc-container. Funny thing though is that I did manage to get some notifications after restarting hass multiple times. So far it only worked once.