From 697833bc917bdfc3db56fe0559c61dbf9bb8ad1f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 22 Dec 2019 10:32:42 +0100 Subject: [PATCH 1/5] Remove requirement from entity integration (#30113) --- .../components/doods/image_processing.py | 2 +- homeassistant/components/doods/manifest.json | 14 +++--- .../components/image_processing/__init__.py | 42 ----------------- .../components/image_processing/manifest.json | 8 +--- .../components/seven_segments/manifest.json | 2 +- .../components/tensorflow/image_processing.py | 2 +- .../components/tensorflow/manifest.json | 7 ++- homeassistant/util/pil.py | 47 +++++++++++++++++++ requirements_all.txt | 4 +- requirements_test_all.txt | 5 -- 10 files changed, 67 insertions(+), 66 deletions(-) create mode 100644 homeassistant/util/pil.py diff --git a/homeassistant/components/doods/image_processing.py b/homeassistant/components/doods/image_processing.py index 7f2c3fd1d42..bd631f757d5 100644 --- a/homeassistant/components/doods/image_processing.py +++ b/homeassistant/components/doods/image_processing.py @@ -15,11 +15,11 @@ from homeassistant.components.image_processing import ( CONF_SOURCE, PLATFORM_SCHEMA, ImageProcessingEntity, - draw_box, ) from homeassistant.core import split_entity_id from homeassistant.helpers import template import homeassistant.helpers.config_validation as cv +from homeassistant.util.pil import draw_box _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/doods/manifest.json b/homeassistant/components/doods/manifest.json index e0dcb48527f..551af839b5c 100644 --- a/homeassistant/components/doods/manifest.json +++ b/homeassistant/components/doods/manifest.json @@ -1,10 +1,8 @@ { - "domain": "doods", - "name": "DOODS - Distributed Outside Object Detection Service", - "documentation": "https://www.home-assistant.io/integrations/doods", - "requirements": [ - "pydoods==1.0.2" - ], - "dependencies": [], - "codeowners": [] + "domain": "doods", + "name": "DOODS - Distributed Outside Object Detection Service", + "documentation": "https://www.home-assistant.io/integrations/doods", + "requirements": ["pydoods==1.0.2", "pillow==6.2.1"], + "dependencies": [], + "codeowners": [] } diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 78ae15eb537..a8f5f0f097e 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -2,9 +2,7 @@ import asyncio from datetime import timedelta import logging -from typing import Tuple -from PIL import ImageDraw import voluptuous as vol from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME, CONF_ENTITY_ID, CONF_NAME @@ -65,46 +63,6 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema) -def draw_box( - draw: ImageDraw, - box: Tuple[float, float, float, float], - img_width: int, - img_height: int, - text: str = "", - color: Tuple[int, int, int] = (255, 255, 0), -) -> None: - """ - Draw a bounding box on and image. - - The bounding box is defined by the tuple (y_min, x_min, y_max, x_max) - where the coordinates are floats in the range [0.0, 1.0] and - relative to the width and height of the image. - - For example, if an image is 100 x 200 pixels (height x width) and the bounding - box is `(0.1, 0.2, 0.5, 0.9)`, the upper-left and bottom-right coordinates of - the bounding box will be `(40, 10)` to `(180, 50)` (in (x,y) coordinates). - """ - - line_width = 3 - font_height = 8 - y_min, x_min, y_max, x_max = box - (left, right, top, bottom) = ( - x_min * img_width, - x_max * img_width, - y_min * img_height, - y_max * img_height, - ) - draw.line( - [(left, top), (left, bottom), (right, bottom), (right, top), (left, top)], - width=line_width, - fill=color, - ) - if text: - draw.text( - (left + line_width, abs(top - line_width - font_height)), text, fill=color - ) - - async def async_setup(hass, config): """Set up the image processing.""" component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL) diff --git a/homeassistant/components/image_processing/manifest.json b/homeassistant/components/image_processing/manifest.json index e986ac6f4ca..1e9f2963a38 100644 --- a/homeassistant/components/image_processing/manifest.json +++ b/homeassistant/components/image_processing/manifest.json @@ -2,11 +2,7 @@ "domain": "image_processing", "name": "Image processing", "documentation": "https://www.home-assistant.io/integrations/image_processing", - "requirements": [ - "pillow==6.2.1" - ], - "dependencies": [ - "camera" - ], + "requirements": [], + "dependencies": ["camera"], "codeowners": [] } diff --git a/homeassistant/components/seven_segments/manifest.json b/homeassistant/components/seven_segments/manifest.json index 0bf49d4b906..6e375da0322 100644 --- a/homeassistant/components/seven_segments/manifest.json +++ b/homeassistant/components/seven_segments/manifest.json @@ -2,7 +2,7 @@ "domain": "seven_segments", "name": "Seven segments", "documentation": "https://www.home-assistant.io/integrations/seven_segments", - "requirements": [], + "requirements": ["pillow==6.2.1"], "dependencies": [], "codeowners": [] } diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index 5f576f176e8..dee2a021829 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -15,11 +15,11 @@ from homeassistant.components.image_processing import ( CONF_SOURCE, PLATFORM_SCHEMA, ImageProcessingEntity, - draw_box, ) from homeassistant.core import split_entity_id from homeassistant.helpers import template import homeassistant.helpers.config_validation as cv +from homeassistant.util.pil import draw_box _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tensorflow/manifest.json b/homeassistant/components/tensorflow/manifest.json index 278a92a481f..627fa8d6bd6 100644 --- a/homeassistant/components/tensorflow/manifest.json +++ b/homeassistant/components/tensorflow/manifest.json @@ -2,7 +2,12 @@ "domain": "tensorflow", "name": "Tensorflow", "documentation": "https://www.home-assistant.io/integrations/tensorflow", - "requirements": ["tensorflow==1.13.2", "numpy==1.17.4", "protobuf==3.6.1"], + "requirements": [ + "tensorflow==1.13.2", + "numpy==1.17.4", + "protobuf==3.6.1", + "pillow==6.2.1" + ], "dependencies": [], "codeowners": [] } diff --git a/homeassistant/util/pil.py b/homeassistant/util/pil.py new file mode 100644 index 00000000000..80c11c9c410 --- /dev/null +++ b/homeassistant/util/pil.py @@ -0,0 +1,47 @@ +"""PIL utilities. + +Can only be used by integrations that have pillow in their requirements. +""" +from typing import Tuple + +from PIL import ImageDraw + + +def draw_box( + draw: ImageDraw, + box: Tuple[float, float, float, float], + img_width: int, + img_height: int, + text: str = "", + color: Tuple[int, int, int] = (255, 255, 0), +) -> None: + """ + Draw a bounding box on and image. + + The bounding box is defined by the tuple (y_min, x_min, y_max, x_max) + where the coordinates are floats in the range [0.0, 1.0] and + relative to the width and height of the image. + + For example, if an image is 100 x 200 pixels (height x width) and the bounding + box is `(0.1, 0.2, 0.5, 0.9)`, the upper-left and bottom-right coordinates of + the bounding box will be `(40, 10)` to `(180, 50)` (in (x,y) coordinates). + """ + + line_width = 3 + font_height = 8 + y_min, x_min, y_max, x_max = box + (left, right, top, bottom) = ( + x_min * img_width, + x_max * img_width, + y_min * img_height, + y_max * img_height, + ) + draw.line( + [(left, top), (left, bottom), (right, bottom), (right, top), (left, top)], + width=line_width, + fill=color, + ) + if text: + draw.text( + (left + line_width, abs(top - line_width - font_height)), text, fill=color + ) diff --git a/requirements_all.txt b/requirements_all.txt index e876b9144de..9ee9b9a740a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -980,9 +980,11 @@ piglow==1.2.4 # homeassistant.components.pilight pilight==0.1.1 -# homeassistant.components.image_processing +# homeassistant.components.doods # homeassistant.components.proxy # homeassistant.components.qrcode +# homeassistant.components.seven_segments +# homeassistant.components.tensorflow pillow==6.2.1 # homeassistant.components.dominos diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 86c3a657988..9b71d8092be 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -320,11 +320,6 @@ pexpect==4.6.0 # homeassistant.components.pilight pilight==0.1.1 -# homeassistant.components.image_processing -# homeassistant.components.proxy -# homeassistant.components.qrcode -pillow==6.2.1 - # homeassistant.components.plex plexapi==3.3.0 From e74c4c5d998d5e3cdd44c204785d5db7ee4b4386 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 22 Dec 2019 10:23:44 +0100 Subject: [PATCH 2/5] Move imports into setup function in homekit __init__.py (#30137) --- homeassistant/components/homekit/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 525c091e177..91d0719e0e7 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -303,6 +303,7 @@ class HomeKit: def setup(self): """Set up bridge and accessory driver.""" + # pylint: disable=import-outside-toplevel from .accessories import HomeBridge, HomeDriver self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop) From e9b19e0465b36c7a41d8e530f0a7b122c2483e0b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 22 Dec 2019 22:24:18 +0100 Subject: [PATCH 3/5] Fix deconz SSDP updating Hassio discovery (#30153) --- homeassistant/components/deconz/config_flow.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index c2035d61d6e..62b8190ff63 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -160,7 +160,11 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): def _update_entry(self, entry, host, port, api_key=None): """Update existing entry.""" - if entry.data[CONF_HOST] == host: + if ( + entry.data[CONF_HOST] == host + and entry.data[CONF_PORT] == port + and (api_key is None or entry.data[CONF_API_KEY] == api_key) + ): return self.async_abort(reason="already_configured") entry.data[CONF_HOST] = host @@ -187,6 +191,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): for entry in self.hass.config_entries.async_entries(DOMAIN): if uuid == entry.data.get(CONF_UUID): + if entry.source == "hassio": + return self.async_abort(reason="already_configured") return self._update_entry( entry, discovery_info[CONF_HOST], entry.data.get(CONF_PORT) ) From 720d63f4961fdb826178e377ab5da4b75f9e0b81 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 22 Dec 2019 22:34:57 +0100 Subject: [PATCH 4/5] Bumped version to 0.103.4 --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index 6239be3cb61..c23ed1cdd03 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -1,7 +1,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 103 -PATCH_VERSION = "3" +PATCH_VERSION = "4" __short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION) __version__ = "{}.{}".format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 6, 1) From 31b17e2b95b82a5c507f26641c92b6f4e3569602 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 22 Dec 2019 22:58:22 +0100 Subject: [PATCH 5/5] Allow battery value of 0 as well as make sure to not create a battery tracker if one already exist (#30155) --- homeassistant/components/deconz/sensor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index 4c854a0ec11..4ffaba9b499 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -59,7 +59,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entity_handler.add_entity(new_sensor) entities.append(new_sensor) - if sensor.battery: + if sensor.battery is not None: new_battery = DeconzBattery(sensor, gateway) if new_battery.unique_id not in batteries: batteries.add(new_battery.unique_id) @@ -225,6 +225,9 @@ class DeconzBatteryHandler: @callback def create_tracker(self, sensor): """Create new tracker for battery state.""" + for tracker in self._trackers: + if sensor == tracker.sensor: + return self._trackers.add(DeconzSensorStateTracker(sensor, self.gateway)) @callback