Load requirements and dependencies from manifests. Fallback to current REQUIREMENTS and DEPENDENCIES (#22717)

* Load dependencies from manifests. Fallback to current DEPENDENCIES

* Fix typing

* Ignore typing correctly

* Split out dependency processing to a new method

* Fix tests

* Only pull from manifest if dependencies is non empty

* Inline temporary function

* Fix light tests [skip ci]

* Fix tests/common

* Fix some mqtt tests [skip ci]

* Fix tests and component manifests which have only one platform

* Fix rflink tests

* Fix more tests and manifests

* Readability over shorthand format

* Fix demo/notify tests

* Load dependencies from manifests. Fallback to current DEPENDENCIES

* Load requirements from manifests. Fallback to current REQUIREMENTS

* Fix typing

* Ignore typing correctly

* Split out dependency processing to a new method

* Only pull from manifest if dependencies is non empty

* Inline temporary function

* Fix tests and component manifests which have only one platform

* Fix rflink tests

* Readability over shorthand format

* Clean up requirements

* Use integration to resolve deps/reqs

* Lint

* Lint

* revert a change

* Revert a test change

* Fix types

* Fix types

* Add back cache for load component

* Fix test_component_not_found

* Move light.test and device_tracker.test into test package instead with manifest to fix tests

* Fix broken device_tracker tests

* Add docstrings to __init__

* Fix all of the light tests that I broke earlier

* Embed the test.switch platform to fix other tests

* Embed and fix the test.imagimage_processing platform

* Fix tests for nx584

* Add dependencies from platform file's DEPENDENCIES

* Try to setup component when entity_platform is setting up

Fix tests in helpers folder

* Rewrite test_setup

* Simplify

* Lint

* Disable demo component if running in test

Temp workaround to unblock CI tests

* Skip demo tests

* Fix config entry test

* Fix repeat test

* Clarify doc

* One extra guard

* Fix import

* Lint

* Workaround google tts
This commit is contained in:
Rohan Kapoor authored and Jason Hu committed 2019-04-11 01:26:36 -07:00
1 parent 8a81286abb
commit 6ba9ccf052
66 files changed
+391 -233

No files matched your search

@@ -0,0 +1,6 @@
{
"state": {
"string1": "German Value 1",
"string2": "German Value 2"
}
}
@@ -0,0 +1,6 @@
{
"state": {
"string1": "Value 1",
"string2": "Value 2"
}
}
@@ -0,0 +1,5 @@
{
"state": {
"string1": "Spanish Value 1"
}
}
@@ -0,0 +1 @@
"""An integration with several platforms used with unit tests."""
@@ -0,0 +1,42 @@
"""Provide a mock device scanner."""
from homeassistant.components.device_tracker import DeviceScanner
def get_scanner(hass, config):
"""Return a mock scanner."""
return SCANNER
class MockScanner(DeviceScanner):
"""Mock device scanner."""
def __init__(self):
"""Initialize the MockScanner."""
self.devices_home = []
def come_home(self, device):
"""Make a device come home."""
self.devices_home.append(device)
def leave_home(self, device):
"""Make a device leave the house."""
self.devices_home.remove(device)
def reset(self):
"""Reset which devices are home."""
self.devices_home = []
def scan_devices(self):
"""Return a list of fake devices."""
return list(self.devices_home)
def get_device_name(self, device):
"""Return a name for a mock device.
Return None for dev1 for testing.
"""
return None if device == 'DEV1' else device.lower()
SCANNER = MockScanner()
@@ -0,0 +1,51 @@
"""Provide a mock image processing."""
from homeassistant.components.image_processing import ImageProcessingEntity
async def async_setup_platform(hass, config, async_add_entities_callback,
discovery_info=None):
"""Set up the test image_processing platform."""
async_add_entities_callback([
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
@@ -0,0 +1,27 @@
"""
Provide a mock light platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.const import STATE_ON, STATE_OFF
from tests.common import MockToggleDevice
DEVICES = []
def init(empty=False):
"""Initialize the platform with devices."""
global DEVICES
DEVICES = [] if empty else [
MockToggleDevice('Ceiling', STATE_ON),
MockToggleDevice('Ceiling', STATE_OFF),
MockToggleDevice(None, STATE_OFF)
]
async def async_setup_platform(hass, config, async_add_entities_callback,
discovery_info=None):
"""Return mock devices."""
async_add_entities_callback(DEVICES)
@@ -0,0 +1,8 @@
{
"domain": "test",
"name": "Test Components",
"documentation": "http://example.com",
"requirements": [],
"dependencies": [],
"codeowners": []
}
@@ -0,0 +1,27 @@
"""
Provide a mock switch platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.const import STATE_ON, STATE_OFF
from tests.common import MockToggleDevice
DEVICES = []
def init(empty=False):
"""Initialize the platform with devices."""
global DEVICES
DEVICES = [] if empty else [
MockToggleDevice('AC', STATE_ON),
MockToggleDevice('AC', STATE_OFF),
MockToggleDevice(None, STATE_OFF)
]
async def async_setup_platform(hass, config, async_add_entities_callback,
discovery_info=None):
"""Find and return test switches."""
async_add_entities_callback(DEVICES)