TypeError: 'bool' object has no attribute '__getitem__'
marcvs opened this issue · 5 comments
Traceback (most recent call last):
File "Plugwise-2.py", line 1467, in <module>
main=PWControl()
File "Plugwise-2.py", line 170, in __init__
self.circles.append(Circle(item['mac'], self.device, item))
File "/srv/plugwise-2-py/plugwise/api.py", line 390, in __init__
self.reinit()
File "/srv/plugwise-2-py/plugwise/api.py", line 400, in reinit
self._get_interval()
File "/srv/plugwise-2-py/plugwise/api.py", line 943, in _get_interval
cur_idx = info['last_logaddr']
TypeError: 'bool' object has no attribute '__getitem__'
I worked around it with this patch, but I'm not aware of side-effects.
diff --git a/plugwise/api.py b/plugwise/api.py
index b60bb1b..8a295f0 100755
--- a/plugwise/api.py
+++ b/plugwise/api.py
@@ -940,6 +940,8 @@ class Circle(object):
self.usage=True
self.production=False
info = self.get_info()
+ if info is False:
+ return
cur_idx = info['last_logaddr']
if cur_idx < 1:
return
The function get_info in api.py returns False in a very specific condition. I consider this to be a really unwanted condition which may be better delt with by raising an exception, but then exception handling needs to be put in place.
The problem occurs when a circle is switched off, while it is configured as AlwaysOn. I used this for critical stuff like the fridge or PV solar installation.
So the question is why is this circle off? Maybe you now first configured it as AlwaysOn = True. It could be caused because in the other config file, pw-control.json, the circle is put to off. Would the problem be resolved if the circle is explicitly set to on and the schedule put to off?
{"mac": "000D6F0001000000", "switch_state": "on", "name": "solar", "schedule_state": "off", ......
I will study the code a bit more to see if I can explicitily turn such a circle on.
Looking at the initialisation code I conclude that above suggestion will not work. It occurs in reading the static configuration from pw-conf.json, and reading the dynamic configuration from pw-control.json only happens later, after the exception already occurred.
I doubt whether I should automatically turn the circle on in case it iis off and defined as always-on. Maybe I should just add a very clear error message to the log file and raise an explicit exception. The code will then crash, but now with clear instructions to resolve the problem in pw-control.json.
The work around is:
- In pw-conf.json set
"always_on": "False"
- In pw-control.json set
"switch_state": "on"
and"schedule_state": "off"
- Start Plugwise2py
- Make sure the intended circle is really switched on.
- In pw-conf.json set
"always_on": "True"
- Restart Plugwise2py
If the circle doesn't turn on in step 4, then try turning it on through the web-interface or through MQTT when you configured an external application.
I suggest to remove the additional code as suggested by @marcvs in order not to hide a real problem. Let me know whether I should force the circle to on, in case it is defined as always_on = true. Otherwise I will add clear logging and raise a clear exception.
@marcvs @Brandjuh @MagnusThome I implemented a solution available at the develop branch 2f0a260
It forces the circle to on in the reinit() function. get_info() no longer returns False, so no special case handling needed anymore.