mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add platform image_processing.qrcode (#20215)
* Add platform image_processing.qrcode * Update qrcode.py
This commit is contained in:
parent
afa019ae47
commit
81a5208762
@ -573,6 +573,7 @@ omit =
|
|||||||
homeassistant/components/image_processing/dlib_face_identify.py
|
homeassistant/components/image_processing/dlib_face_identify.py
|
||||||
homeassistant/components/image_processing/seven_segments.py
|
homeassistant/components/image_processing/seven_segments.py
|
||||||
homeassistant/components/image_processing/tensorflow.py
|
homeassistant/components/image_processing/tensorflow.py
|
||||||
|
homeassistant/components/image_processing/qrcode.py
|
||||||
homeassistant/components/keyboard_remote.py
|
homeassistant/components/keyboard_remote.py
|
||||||
homeassistant/components/keyboard.py
|
homeassistant/components/keyboard.py
|
||||||
homeassistant/components/light/avion.py
|
homeassistant/components/light/avion.py
|
||||||
|
69
homeassistant/components/image_processing/qrcode.py
Normal file
69
homeassistant/components/image_processing/qrcode.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
"""
|
||||||
|
Support for the QR image processing.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/image_processing.qr/
|
||||||
|
"""
|
||||||
|
from homeassistant.core import split_entity_id
|
||||||
|
from homeassistant.components.image_processing import (
|
||||||
|
ImageProcessingEntity, CONF_SOURCE, CONF_ENTITY_ID, CONF_NAME)
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pyzbar==0.1.7', 'pillow==5.4.1']
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
"""Set up the demo image processing platform."""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
entities = []
|
||||||
|
for camera in config[CONF_SOURCE]:
|
||||||
|
entities.append(QrEntity(
|
||||||
|
camera[CONF_ENTITY_ID], camera.get(CONF_NAME)
|
||||||
|
))
|
||||||
|
|
||||||
|
add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class QrEntity(ImageProcessingEntity):
|
||||||
|
"""QR image processing entity."""
|
||||||
|
|
||||||
|
def __init__(self, camera_entity, name):
|
||||||
|
"""Initialize QR image processing entity."""
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self._camera = camera_entity
|
||||||
|
if name:
|
||||||
|
self._name = name
|
||||||
|
else:
|
||||||
|
self._name = "QR {0}".format(
|
||||||
|
split_entity_id(camera_entity)[1])
|
||||||
|
self._state = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def camera_entity(self):
|
||||||
|
"""Return camera entity id from process pictures."""
|
||||||
|
return self._camera
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the entity."""
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the entity."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def process_image(self, image):
|
||||||
|
"""Process image."""
|
||||||
|
import io
|
||||||
|
from pyzbar import pyzbar
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
stream = io.BytesIO(image)
|
||||||
|
img = Image.open(stream)
|
||||||
|
|
||||||
|
barcodes = pyzbar.decode(img)
|
||||||
|
if barcodes:
|
||||||
|
self._state = barcodes[0].data.decode("utf-8")
|
||||||
|
else:
|
||||||
|
self._state = None
|
@ -789,6 +789,7 @@ piglow==1.2.4
|
|||||||
pilight==0.1.1
|
pilight==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.camera.proxy
|
# homeassistant.components.camera.proxy
|
||||||
|
# homeassistant.components.image_processing.qrcode
|
||||||
# homeassistant.components.image_processing.tensorflow
|
# homeassistant.components.image_processing.tensorflow
|
||||||
pillow==5.4.1
|
pillow==5.4.1
|
||||||
|
|
||||||
@ -1397,6 +1398,9 @@ pyxeoma==1.4.0
|
|||||||
# homeassistant.components.zabbix
|
# homeassistant.components.zabbix
|
||||||
pyzabbix==0.7.4
|
pyzabbix==0.7.4
|
||||||
|
|
||||||
|
# homeassistant.components.image_processing.qrcode
|
||||||
|
pyzbar==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.sensor.qnap
|
# homeassistant.components.sensor.qnap
|
||||||
qnapstats==0.2.7
|
qnapstats==0.2.7
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user