@PuckStar just to be complete, the reason you got the exception is because you are missing the gasUsage portion in your state. That is considered required in the library.
@krocat I pushed a new version that disables the switches if they cannot be toggled. I have an MR for you. If anyone wants to test this choose the Smart-Plugs-integration branch.
Hi @costas, thanks for all the great work. Iāll test in a minute. Regarding the config items, I guess we could do both. The default behavior would be based on discovery, but users would have the ability using optional config parameters that force items on or off. I have smoke detectors by the way. This is what it looks like in the json feed:
u'smokeDetectors': {
u'device': [
{
u'devUuid': u'eneco-xxx-xxxxx:hdrv_zwave_xxxxxxxxxx',
u'name': u'Overloop',
u'lastConnectedChange': 1490968398,
u'connected': 1,
u'batteryLevel': 100,
u'type': u'FGSS001'
},
{
u'devUuid': u'eneco-xxx-xxxxx:hdrv_zwave_xxxxxxxxxx',
u'name': u'Hal',
u'lastConnectedChange': 1490968398,
u'connected': 1,
u'batteryLevel': 100,
u'type': u'FGSS001'
},
{
u'devUuid': u'eneco-xxx-xxxxx:hdrv_zwave_xxxxxxxxxx',
u'name': u'Woonkamer',
u'lastConnectedChange': 1490968398,
u'connected': 1,
u'batteryLevel': 100,
u'type': u'FGSS001'
}
]
},
Lovely on both accounts. Super in with the option of turning things off. Adding smoke detectors in a while Thanks!
Iāll try the new version tonight when Iām back home.
Regarding the smoke detectors I now have them hooked up directly to Home Assistant so I can trigger many things when smoke is detected (send notification, turn all lights on and to full brightness, open rollershutter).
If the detector is linked to Toon can I then also configure these triggers in HASS?
I asked fibaro but the detectors can only be linked to 1 system, so either Toon or Home Automation.
Hi @krocat. I added smokedetectors to the library. If you could be so kind as to test if the latest commit on github works fine for you I will package it and upload it to pypi as 0.5.0 and then we can see how to add them to the component.
@krocat could you please have a look into your toon._state under deviceConfigInfo and deviceStatusInfo for relevant to the smokedetectors entries, because I think that the info exposed under smokedetectors is very generic to be of any use. How do the smokedetectors publish their state? I am guessing that something exists under the mentioned keys.
Iām having difficulty keeping up with you today @costas, youāre on a roll Those two sections that you mention only contain Hue lights in my case. I think whether or not the smoke detector is connected and battery level is all weāll get from them. Itās the same in the Toon app. When smoke is detected, I get a call and a text message and a message is displayed on Toon, this may be something they do outside the API. Itās not super useful, but itās nice to have a complete Toon experience with this component.
Regarding the smoke detectors if smoke detection is not passed through the API and we canāt use it for triggers in Home Assistant then I wonāt connect them to Toon but rather keep them connected directly to Home Assistant.
If youāre unsure if itās passed or not I could try to trigger the detector and see what is passed through but I need some help in how Iāll be able to (in realtime) see whatās passing the API.
As Toon supports getting a call when there is smoke I prefer to have that solution initially. In HASS I can do the lights on etc. but donāt have a ācall my mobileā component.
@krocat sorry, its a slow day for me so i was having funā¦ putting it to rest nowā¦ @PuckStar if you want to help with this I suggest you setup a local virtualenv and install toonlib there. Lower the caching for the library to 2 seconds or something. You can do that on the configuration.py in the path of your virtualenv (in my case its under ~/.virtualenvs/toonlib/lib/python2.7/site-packages/toonlib/configuration.py). Through a python console interactively instantiate the object enabling debug output, something like
import logging
logging.basicConfig(level=logging.DEBUG)
username=āUSERNAMEā
password=āPASSWORDā
from toonlib import Toon
toon=Toon(username, password)
print(toon._state)
Trigger your smoke detector
and do a few
print(toon._state)
and post the output of those prints for us to have a look.
@costas, I think I just had another incomplete response. The component still fails, unfortunately and with a less intuitive error than before. It looks like powerUsage did not come through, can you check if you default these to zero?
17-04-26 15:09:30 ERROR (MainThread) [homeassistant.setup] Error during setup of component toon
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 192, in _async_setup_component
None, component.setup, hass, processed_config)
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 52, in setup
solar)
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 83, in __init__
self.update()
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 87, in update
self.data['power_current'] = self.toon.power.value
File "/home/homeassistant/.homeassistant/deps/toonlib/toonlib.py", line 238, in power
power = self._state['powerUsage']
File "/home/homeassistant/.homeassistant/deps/cachetools/__init__.py", line 46, in wrapper
v = func(*args, **kwargs)
File "/home/homeassistant/.homeassistant/deps/toonlib/toonlib.py", line 167, in _state
state.update(self._get_data('/client/auth/retrieveToonState'))
File "/home/homeassistant/.homeassistant/deps/toonlib/toonlib.py", line 187, in _get_data
return response.json()
File "/srv/homeassistant/lib/python3.4/site-packages/requests/models.py", line 866, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
that is probably your session being invalidatedā¦ This is what I am trying to get to in my debugging setup so i can solve it.
What this says is that in line 187 we try to return response.json() which of course internally calls the json library. But seeing as there is no json response (we probably have an error code and a message in response.text) the json library borks. Nothing to do with incomplete response I think.
I received it when restarting HA, I wouldnāt expect a session timeout at that stageā¦
Following is my debugging changes in toonlib to catch the de authentication. Line 177 of toonlib.py
def _get_data(self, endpoint, params=None):
url = '{base}{endpoint}'.format(base=self.base_url,
endpoint=endpoint)
response = requests.get(url, params=params or self._parameters) # noqa
if not response.ok:
self._logger.error(('\n\tStatus Code :{}'
'\n\tText :{}').format(response.status_code,
response.text))
return None
try:
return response.json()
except Exception:
self._logger.exception(('\n\tStatus Code :{}'
'\n\tText :{}').format(response.status_code,
response.text))
It might be an incomplete authentication request. I have had a few 500 from the api. Sadly, very flakyā¦ Try to add that method in your code so when it breaks we get something better. I am also looking at the same place. We will fix it in due timeā¦ We just need the data
Actually i just added that to the library. if the smokedetectors work for you i can make a new version, we can bump the dependency on the component and anyone having any problem will give us some useful insights on what happens there. Once we fix it we can revert the broad exception handling on the next version with the fix in.
Hi @costas, this looks like a bug in the library:
17-04-26 16:53:39 ERROR (MainThread) [homeassistant.setup] Error during setup of component toon
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 192, in _async_setup_component
None, component.setup, hass, processed_config)
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 52, in setup
solar)
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 83, in __init__
self.update()
File "/home/homeassistant/.homeassistant/custom_components/toon.py", line 120, in update
for sd in self.toon.smokedetectors:
File "/home/homeassistant/.homeassistant/deps/toonlib/toonlib.py", line 206, in smokedetectors
{}).get('device', [])]
File "/home/homeassistant/.homeassistant/deps/toonlib/toonlib.py", line 205, in <listcomp>
for smokedetector in self._state.get('smokeDetectors',
TypeError: __new__() takes 7 positional arguments but 8 were given
Yeah, and I know where it is.I will fix it in half an hour and get back to you.currently in transit.
I pushed the fix. In line 198 of toonlib you can remove the self argument if you want to fix it locally. @krocat