mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Move part of image_processing tests (#5634)
* Move part of image_processing tests * fix lint
This commit is contained in:
parent
24f828d7eb
commit
261ffbbfea
@ -5,7 +5,6 @@ For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/demo/
|
||||
"""
|
||||
|
||||
from homeassistant.components.image_processing import ImageProcessingEntity
|
||||
from homeassistant.components.image_processing.openalpr_local import (
|
||||
ImageProcessingAlprEntity)
|
||||
from homeassistant.components.image_processing.microsoft_face_identify import (
|
||||
@ -15,42 +14,12 @@ from homeassistant.components.image_processing.microsoft_face_identify import (
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the demo image_processing platform."""
|
||||
add_devices([
|
||||
DemoImageProcessing('camera.demo_camera', "Demo"),
|
||||
DemoImageProcessingAlpr('camera.demo_camera', "Demo Alpr"),
|
||||
DemoImageProcessingFaceIdentify(
|
||||
'camera.demo_camera', "Demo Face Identify")
|
||||
])
|
||||
|
||||
|
||||
class DemoImageProcessing(ImageProcessingEntity):
|
||||
"""Demo alpr image processing entity."""
|
||||
|
||||
def __init__(self, camera_entity, name):
|
||||
"""Initialize demo alpr."""
|
||||
self._name = name
|
||||
self._camera = camera_entity
|
||||
self._count = 0
|
||||
|
||||
@property
|
||||
def camera_entity(self):
|
||||
"""Return camera entity id from process pictures."""
|
||||
return self._camera
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
return self._count
|
||||
|
||||
def process_image(self, image):
|
||||
"""Process image."""
|
||||
self._count += 1
|
||||
|
||||
|
||||
class DemoImageProcessingAlpr(ImageProcessingAlprEntity):
|
||||
"""Demo alpr image processing entity."""
|
||||
|
||||
|
@ -61,17 +61,14 @@ class TestImageProcessing(object):
|
||||
|
||||
config = {
|
||||
ip.DOMAIN: {
|
||||
'platform': 'demo'
|
||||
'platform': 'test'
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
}
|
||||
|
||||
with patch('homeassistant.components.image_processing.demo.'
|
||||
'DemoImageProcessing.should_poll',
|
||||
new_callable=PropertyMock(return_value=False)):
|
||||
setup_component(self.hass, ip.DOMAIN, config)
|
||||
setup_component(self.hass, ip.DOMAIN, config)
|
||||
|
||||
state = self.hass.states.get('camera.demo_camera')
|
||||
self.url = "{0}{1}".format(
|
||||
@ -84,33 +81,32 @@ class TestImageProcessing(object):
|
||||
|
||||
@patch('homeassistant.components.camera.demo.DemoCamera.camera_image',
|
||||
autospec=True, return_value=b'Test')
|
||||
@patch('homeassistant.components.image_processing.demo.'
|
||||
'DemoImageProcessing.process_image', autospec=True)
|
||||
def test_get_image_from_camera(self, mock_process, mock_camera):
|
||||
def test_get_image_from_camera(self, mock_camera):
|
||||
"""Grab a image from camera entity."""
|
||||
self.hass.start()
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo')
|
||||
ip.scan(self.hass, entity_id='image_processing.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert mock_camera.called
|
||||
assert mock_process.called
|
||||
state = self.hass.states.get('image_processing.test')
|
||||
|
||||
assert mock_process.call_args[0][1] == b'Test'
|
||||
assert mock_camera.called
|
||||
assert state.state == '1'
|
||||
assert state.attributes['image'] == b'Test'
|
||||
|
||||
@patch('homeassistant.components.camera.async_get_image',
|
||||
side_effect=HomeAssistantError())
|
||||
@patch('homeassistant.components.image_processing.demo.'
|
||||
'DemoImageProcessing.process_image', autospec=True)
|
||||
def test_get_image_without_exists_camera(self, mock_process, mock_image):
|
||||
def test_get_image_without_exists_camera(self, mock_image):
|
||||
"""Try to get image without exists camera."""
|
||||
self.hass.states.remove('camera.demo_camera')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo')
|
||||
ip.scan(self.hass, entity_id='image_processing.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test')
|
||||
|
||||
assert mock_image.called
|
||||
assert not mock_process.called
|
||||
assert state.state == '0'
|
||||
|
||||
|
||||
class TestImageProcessingAlpr(object):
|
||||
|
@ -0,0 +1,49 @@
|
||||
"""Provide a mock image processing."""
|
||||
|
||||
from homeassistant.components.image_processing import ImageProcessingEntity
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the test image_processing platform."""
|
||||
add_devices([TestImageProcessing('camera.demo_camera', "Test")])
|
||||
|
||||
|
||||
class TestImageProcessing(ImageProcessingEntity):
|
||||
"""Test image processing entity."""
|
||||
|
||||
def __init__(self, camera_entity, name):
|
||||
"""Initialize test image processing."""
|
||||
self._name = name
|
||||
self._camera = camera_entity
|
||||
self._count = 0
|
||||
self._image = ""
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return True if entity has to be polled for state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def camera_entity(self):
|
||||
"""Return camera entity id from process pictures."""
|
||||
return self._camera
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
return self._count
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
return {'image': self._image}
|
||||
|
||||
def process_image(self, image):
|
||||
"""Process image."""
|
||||
self._image = image
|
||||
self._count += 1
|
Loading…
x
Reference in New Issue
Block a user