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.42k stars 29.9k forks source link

dlib: AttributeError: 'tuple' object has no attribute 'update' #8493

Closed patvdleer closed 7 years ago

patvdleer 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.1

Python release (python3 --version): Python 3.5.2

Component/platform: image_processing/dlib_face_detect

Description of problem: Error in code for automation

Expected:

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

# camera: !include_dir_list camera
camera:
  platform: mjpeg
  name: Voordeur
  mjpeg_url: http://192.168.178.18/videostream.cgi?user=admin&pwd=admin

image_processing:
  - platform: dlib_face_detect
    source:
      - entity_id: camera.voordeur

automations:
- id: face_detect_frontdoor
  alias: Someone is at the door
  trigger:
    platform: event
    event_type: image_processing.detect_face
    event_data:
      entity_id: image_processing.voordeur
  action:
    service: notify.pushbullet
    data: 
      title: 'Someone is at the door'
      message: "Someone is at the door"

Traceback (if applicable):

2017-07-15 20:43:39 ERROR (MainThread) [homeassistant.helpers.entity] Update for image_processing.dlib_face_garage fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 222, in async_update_ha_state
    yield from self.async_update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/image_processing/__init__.py", line 140, in async_update
    yield from self.async_process_image(image)
  File "uvloop/future.pyx", line 230, in __iter__ (uvloop/loop.c:110600)
  File "uvloop/future.pyx", line 432, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:113980)
  File "uvloop/future.pyx", line 101, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:108900)
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/image_processing/dlib_face_detect.py", line 71, in process_image
    self.process_faces(face_locations, len(face_locations))
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/image_processing/microsoft_face_identify.py", line 111, in process_faces
    self.hass.loop, self.async_process_faces, faces, total).result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 405, in result
    return self.__get_result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/util/async.py", line 167, in run_callback
    future.set_result(callback(*args))
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/image_processing/microsoft_face_identify.py", line 137, in async_process_faces
    face.update({ATTR_ENTITY_ID: self.entity_id})
AttributeError: 'tuple' object has no attribute 'update'

Additional info: https://community.home-assistant.io/t/question-on-dlib-component/17352/14

arsaboo commented 7 years ago

Dlib was bumped to 0.2.0 in 0.49. Can you please check if the issue is fixed in 0.49 and report..thanks!

pvizeli commented 7 years ago

Yeah look like a bug. I try to fix it for 0.49.1

tchellomello commented 7 years ago

@pvizeli I've started some work already on this as mentioned at https://community.home-assistant.io/t/question-on-dlib-component/17352/15?u=tchellomello.

On my tests at https://github.com/tchellomello/home-assistant/tree/dlib_troubleshooting instead fixing the method async_process_faces directly on microsoft components, I moved to dlib itself to don't break the microsoft one.

Also I thought and started extending the dlib componenet so it can save images during the configuration/troubleshooting process.

Another problem that I noticed is that the face attribute is not displaying the face[ATTR_NAME] but an object instead.

tchellomello commented 7 years ago

@patvdleer @pvizeli created a PR #8515 based on some tests and work that I was already playing with. Please let me know what you think.

pvizeli commented 7 years ago

https://github.com/home-assistant/home-assistant/pull/8517

patvdleer commented 7 years ago

What a progress!

@tchellomello will test this tonight when I get home.

patvdleer commented 7 years ago

Seems like the detection does work now but the event isn't triggered.

hass --version
0.50.0.dev0

CONFIG

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: 63
  unit_system: metric
  time_zone: Europe/Amsterdam

frontend:
http:
recorder:
updater:
config:
discovery:
conversation:
history:
logbook:

notify:
  - name: PushBullet
    platform: pushbullet
    api_key: !secret pushbullet_api_key

automation:
- id: face_detect_my_file
  alias: Someone is in the file
  trigger:
  - event_data:
      entity_id: image_processing.my_file
    event_type: image_processing.detect_face
    platform: event
  action:
  - service: notify.pushbullet
    data:
      message: Someone is at the door
      title: Someone is at the door

camera:
  - platform: local_file
    name: my_file
    file_path: /tmp/image.jpg

image_processing:
  - platform: dlib_face_detect
    source:
      - entity_id: camera.my_file

zone 1:
  name: Home
  latitude: !secret latitude
  longitude: !secret longitude
  radius: 100
  icon: mdi:home
INFO:homeassistant.components.http:Serving /api/camera_proxy/camera.my_file to 127.0.0.1 (auth: True)
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=image_processing.dlib_face_my_file, old_state=<state image_processing.dlib_face_my_file=0; total_faces=0, friendly_name=Dlib Face my_file, device_class=face @ 2017-07-17T22:10:10.136448+02:00>, new_state=<state image_processing.dlib_face_my_file=3; total_faces=3, friendly_name=Dlib Face my_file, device_class=face @ 2017-07-17T22:10:31.138673+02:00>>

INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=image_processing.dlib_face_my_file, old_state=<state image_processing.dlib_face_my_file=3; total_faces=3, friendly_name=Dlib Face my_file, device_class=face @ 2017-07-17T22:12:14.655277+02:00>, new_state=<state image_processing.dlib_face_my_file=2; total_faces=2, friendly_name=Dlib Face my_file, device_class=face @ 2017-07-17T22:13:28.891326+02:00>>