Add sighthound save image (#32103)

* Adds save_image

* Update test_image_processing.py

* Update test

* Tidy test

* update image_processing with reviewer comments

* Update test_image_processing.py

* Ammend tests

not passing

* Patch convert

* remove join

* Use valid_config_save_file
This commit is contained in:
Robin authored and GitHub committed 2020-02-23 19:11:05 +01:00
1 parent f6fbecf963
commit 4cc4f070f5
2 files changed
+52 -2

No files matched your search

@@ -1,4 +1,6 @@
"""Tests for the Sighthound integration."""
from copy import deepcopy
import os
from unittest.mock import patch
import pytest
@@ -10,6 +12,8 @@ from homeassistant.const import ATTR_ENTITY_ID, CONF_API_KEY
from homeassistant.core import callback
from homeassistant.setup import async_setup_component
TEST_DIR = os.path.dirname(__file__)
VALID_CONFIG = {
ip.DOMAIN: {
"platform": "sighthound",
@@ -91,3 +95,23 @@ async def test_process_image(hass, mock_image, mock_detections):
state = hass.states.get(VALID_ENTITY_ID)
assert state.state == "2"
assert len(person_events) == 2
async def test_save_image(hass, mock_image, mock_detections):
"""Save a processed image."""
valid_config_save_file = deepcopy(VALID_CONFIG)
valid_config_save_file[ip.DOMAIN].update({sh.CONF_SAVE_FILE_FOLDER: TEST_DIR})
await async_setup_component(hass, ip.DOMAIN, valid_config_save_file)
assert hass.states.get(VALID_ENTITY_ID)
with patch(
"homeassistant.components.sighthound.image_processing.Image.open"
) as pil_img_open:
pil_img = pil_img_open.return_value
pil_img = pil_img.convert.return_value
data = {ATTR_ENTITY_ID: VALID_ENTITY_ID}
await hass.services.async_call(ip.DOMAIN, ip.SERVICE_SCAN, service_data=data)
await hass.async_block_till_done()
state = hass.states.get(VALID_ENTITY_ID)
assert state.state == "2"
assert pil_img.save.call_count == 1