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.05k stars 29.71k forks source link

Logger not working when axis and remote components are enabled #8297

Closed theFeverDog closed 6 years ago

theFeverDog commented 7 years ago

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version): 0.48.0

Python release (python3 --version): 3.4.2

Component/platform: axis / remote (harmony) / Logger

Description of problem: When enabling both the component Harmony Remote and Axis Camera, the Logger component throws an exception and no state changes are recorded. Both the Harmony and the Axis Camera functions can be used as expected.

When disabling the Axis Camera component again, this behavior does not occur.

Expected: The logger component works normally.

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


remote:
  - platform: harmony
    name: Living
    host: [ip]

axis:
  axis_front:
    host: [ip]
    username: hass
    password: !secret camera
    include:
    - camera
    trigger_time: 0

Traceback (if applicable):


ERROR:homeassistant.core:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/remote.py", line 132, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <homeassistant.core.HomeAssistant object at 0x76aaed30> is not JSON serializable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/remote.py", line 138, in default
    for child_obj in obj]
TypeError: 'HomeAssistant' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/components/api.py", line 104, in forward_events
    data = json.dumps(event, cls=rem.JSONEncoder)
  File "/usr/lib/python3.4/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.4/json/encoder.py", line 192, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.4/json/encoder.py", line 250, in iterencode
    return _iterencode(o, 0)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/remote.py", line 141, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <homeassistant.core.HomeAssistant object at 0x76aaed30> is not JSON serializable
ERROR:homeassistant.components.recorder.util:Error executing query: <homeassistant.core.HomeAssistant object at 0x76aaed30> is not JSON serializable
ERROR:homeassistant.core:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/remote.py", line 132, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <homeassistant.core.HomeAssistant object at 0x76aaed30> is not JSON serializable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/remote.py", line 138, in default
    for child_obj in obj]
TypeError: 'HomeAssistant' object is not iterable

Additional info:

Traceback seems to repeat for several times if discovery is used to add the camera. When adding the camera manually in the YAML, the error only occurs once.

Kane610 commented 7 years ago

I'm gonna look at this from the axis component point of view shortly.

theFeverDog commented 7 years ago

This is still applicable for 0.49. I tried excluding some components from the logger but without success.

theFeverDog commented 7 years ago

This seems to be related with this issue with recorder/amcrest #8551

boojew commented 7 years ago

I have this same issue. I am using the Axis component, but not any remote component

boojew commented 7 years ago

Issue appears to be solved on the Armcrest component. Any word on this one

Kane610 commented 7 years ago

I haven't spent any time the last couple of months on automation. Will try to get my environment back up tomorrow evening. I think I know whats causing the issue but not how to solve it yet.

Kane610 commented 7 years ago

So I have a fix for this, all creds to @tchellomello who I just copied the solution for this issue from :)

If you guys wanna try it out you can find it here https://pypi.python.org/pypi/axis/9

boojew commented 7 years ago

@Kane610 I would be happy to test, but I'm not clear on what needs to be done.

Nevermind.. I figured it out.. Testing now

pip3 install --upgrade axis

boojew commented 7 years ago

Ok, tested I still see the same issue. When I remove the Axis component, i get logging. But when I reinstate it, I get this problem. I did the pip3 upgrade, but since I'm using docker, I also copied the files to /config/deps/lib/python3.6/site-packages

I also still get 2017-09-01 17:23:16 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: Object of type 'HomeAssistant' is not JSON serializable

Not sure if maybe I didnt do something correctly..

Kane610 commented 7 years ago

I upped the version number. That might have something to with it. Just change version to 8 in the setup.py. Don't you have a deps folder in your home assistant folder? I have no experience with docker yet.

wilfredsmit commented 7 years ago

Installed the Axis update. Problem still exist. I'm on Hassbian version 0.52.1. This is my log entry.

2017-09-03 15:50:01 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: <homeassistant.core.HomeAssistant object at 0x76a64a70> is not JSON serializable

Kane610 commented 7 years ago

Ok, did you change the version number to 8 since hass won't use it otherwise. Can you verify that at the bottom of the init.py file there is a function called as_dict(self)?

wilfredsmit commented 7 years ago

Oké, how do I check this? In the directory /srv/homeassistant/lib/python3.4/site-packages/axis/ there is a file init.py. The last function in this file is is_tripped(self).

I do the following:

pip3 install --upgrade axis

Collecting axis
  Using cached axis-9.tar.gz
Collecting requests (from axis)
  Using cached requests-2.18.4-py2.py3-none-any.whl
Requirement already up-to-date: certifi>=2017.4.17 in /srv/homeassistant/lib/python3.4/site-packages (from requests->axis)
Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /srv/homeassistant/lib/python3.4/site-packages (from requests->axis)
Requirement already up-to-date: idna<2.7,>=2.5 in /srv/homeassistant/lib/python3.4/site-packages (from requests->axis)
Requirement already up-to-date: urllib3<1.23,>=1.21.1 in /srv/homeassistant/lib/python3.4/site-packages (from requests->axis)
Installing collected packages: requests, axis
  Found existing installation: requests 2.14.2
    Uninstalling requests-2.14.2:
      Successfully uninstalled requests-2.14.2
  Found existing installation: axis 8
    Uninstalling axis-8:
      Successfully uninstalled axis-8
  Running setup.py install for axis ... done
Successfully installed axis-9 requests-2.18.4

If I now check the file /srv/homeassistant/lib/python3.4/site-packages/axis/init.py, then the function as_dict(self) does exist. But after a reboot of the Pi3 it's all gone again.

Is there something I do wrong?

Kane610 commented 7 years ago

You don't need to reboot the pi only hass. My guess is that Hass only allows v8 of the axis component, and you're installing v9. What you need to do is to change version number to 8 in the setup.py prior to installing it.

wilfredsmit commented 7 years ago

I've downloaded version 9 on my Pi3 changed the version number in setup.py. But how do I install it?

Kane610 commented 7 years ago

pip install PATH1 --target PATH2 --upgrade Where PATH1 is the folder path to your downloaded axis component and PATH2 is the path to HASS deps folder which is either in your .homeassistant or in your sitepackages if you're running venv (in my case it is /home/pi/home-assistant/venv/lib/python3.4/site-packages/)

wilfredsmit commented 7 years ago

I've managed to install version 9 as version 8. At the bottom of the init.py file there is a function called as_dict(self), even after a HA restart. But unfortunately HA still has the same JSON error.

Kane610 commented 7 years ago

Would you mind doing one last thing? Put a _LOGGER.warning("Something something") on the line after as_dict(self). Just to verify that it is actually run. Else it would mean that the package is failing to install. Since it all worked well with all things enabled on my computer.

wilfredsmit commented 7 years ago

Good morning Kane,

I've done what you asked. The package has installed, because when I restart HA, the following entry appears in the logfile:

sep 04 09:10:42 hassbian hass[24861]: File "/srv/homeassistant/lib/python3.4/site-packages/axis/__init__.py", line 300
**sep 04 09:10:42 hassbian hass[24861]: _LOGGER.warning("Dit is een check om te zien of het script heeft gewerkt!")**
sep 04 09:10:42 hassbian hass[24861]: ^
sep 04 09:10:42 hassbian hass[24861]: IndentationError: unindent does not match any outer indentation level
Kane610 commented 7 years ago

Well, thats good at least... But annoyed since it seems the fix doesn't solve it... You still get the json error?

wilfredsmit commented 7 years ago

That's correct. When I remove the _LOGGER.warning and restart HA, the Axis camera works without a problem. Though the recorder doesn't work and the error still exist.

Kane610 commented 7 years ago

Nevermind, I enabled the camera part of the axis component and got new issues, probably what you're seeing.

wilfredsmit commented 7 years ago

Done it. The last function looks like this:

    def as_dict(self):
        """Callback for __dict__."""
        cdict = self.__dict__.copy()
        del cdict['callback']
        del cdict['_device']
        _LOGGER.warning('%s', cdict)
        return cdict 

No difference, this is what I get when restarting HA:

home-assistant@homeassistant.service - Home Assistant for homeassistant
   Loaded: loaded (/etc/systemd/system/home-assistant@homeassistant.service; enabled)
   Active: active (running) since ma 2017-09-04 09:42:14 CEST; 1min 34s ago
 Main PID: 25931 (hass)
   CGroup: /system.slice/system-home\x2dassistant.slice/home-assistant@homeassistant.service
           ├─25931 /srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass
           └─26144 nmap -oX - 192.168.2.1/24 -F --host-timeout 5s --exclude 192.168.2.30,192.168.2.10,192.168.2.2,192.168.2.73,192.168.2.250,192.168.2.252,192.168.2.254,192.168.2.3,192.168.2.20,192.168.2.235,192.168.2.71,192.168.2.143,192.168.2.205,192.168.2.238,192.168.2.251,192.168.2.86,192.168.2.72,192.168.2.125,192.168.2.5,192.168.2.88,192.168.2.253,192.168.2.7,192.168.2.6,192.168.2.118,192.168.2.1,192.168.2.81,192.168.2.123,192.168.2.85,192.168.2.121

sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=check_config, domain=homeassistant>
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=reload_core_config, domain=homeassistant>
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=create, domain=persistent_notification>
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=dismiss, domain=persistent_notification>
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger
sep 04 09:42:21 hassbian hass[25931]: 2017-09-04 09:42:21 INFO (MainThread) [homeassistant.setup] Setting up logger
sep 04 09:42:55 hassbian hass[25931]: 2017-09-04 09:42:55 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: <homeassistant.core.HomeAssistant object at 0x769c0a70> is not JSON serializable
Kane610 commented 7 years ago

I think I found the issue. I thought it was only the events that triggered this issue, but it was the camera component as well. And I have a different thing you could try if you want to. This would be the last time if it proves to work. In your local components/axis.py file

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/axis.py#L239

Replace that line with clean_config = config.copy() del clean_config['hass'] discovery.load_platform(hass, component, DOMAIN, clean_config) remember to keep indentation.

wilfredsmit commented 7 years ago

I've altered this file: /srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/axis.py

Replaced line 239:

            discovery.load_platform(hass, component, DOMAIN, config)

with:

            clean_config = config.copy()
            del clean_config['hass']
            discovery.load_platform(hass, component, DOMAIN, clean_config)

Then I restarted HA and got an error on the Axis component. HA says: Invalid Config. The following components and platforms could not be set up: axis.

The error log shows:

home-assistant@homeassistant.service - Home Assistant for homeassistant
   Loaded: loaded (/etc/systemd/system/home-assistant@homeassistant.service; enabled)
   Active: active (running) since ma 2017-09-04 10:49:30 CEST; 42s ago
 Main PID: 27767 (hass)
   CGroup: /system.slice/system-home\x2dassistant.slice/home-assistant@homeassistant.service
           └─27767 /srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass

sep 04 10:49:42 hassbian hass[27767]: value = future.result()
sep 04 10:49:42 hassbian hass[27767]: File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
sep 04 10:49:42 hassbian hass[27767]: raise self._exception
sep 04 10:49:42 hassbian hass[27767]: File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
sep 04 10:49:42 hassbian hass[27767]: result = self.fn(*self.args, **self.kwargs)
sep 04 10:49:42 hassbian hass[27767]: File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/axis.py", line 189, in setup
sep 04 10:49:42 hassbian hass[27767]: if not setup_device(hass, config):
sep 04 10:49:42 hassbian hass[27767]: File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/axis.py", line 220, in setup_device
sep 04 10:49:42 hassbian hass[27767]: from axis import AxisDevice
sep 04 10:49:42 hassbian hass[27767]: ImportError: cannot import name 'AxisDevice'
Kane610 commented 7 years ago

Hmm, that shouldn't happen. That would be related to the external component which you didn't do anything with

wilfredsmit commented 7 years ago

After a reboot of the Pi3 the log file shows:

2017-09-04 10:57:16 ERROR (MainThread) [homeassistant.setup] Error during setup of component axis
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 194, in _async_setup_component
    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 "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/axis.py", line 189, in setup
    if not setup_device(hass, config):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/axis.py", line 220, in setup_device
    from axis import AxisDevice
ImportError: cannot import name 'AxisDevice'
Kane610 commented 7 years ago

Ok, revert your changes back so it works for you. I think I got all gates covered. Thanks for your help Wilfred!