Clean up Google Config (#24663)
* Clean up Google Config * Lint * pylint * pylint2
This commit is contained in:
1 parent
d468d0f71b
commit
78b7ed0ebe
12 files changed
+460
-387
No files matched your search
@@ -1,6 +1,33 @@
|
||||
|
||||
|
||||
"""Tests for the Google Assistant integration."""
|
||||
from homeassistant.components.google_assistant import helpers
|
||||
|
||||
|
||||
class MockConfig(helpers.AbstractConfig):
|
||||
"""Fake config that always exposes everything."""
|
||||
|
||||
def __init__(self, *, secure_devices_pin=None, should_expose=None,
|
||||
entity_config=None):
|
||||
"""Initialize config."""
|
||||
self._should_expose = should_expose
|
||||
self._secure_devices_pin = secure_devices_pin
|
||||
self._entity_config = entity_config or {}
|
||||
|
||||
@property
|
||||
def secure_devices_pin(self):
|
||||
"""Return secure devices pin."""
|
||||
return self._secure_devices_pin
|
||||
|
||||
@property
|
||||
def entity_config(self):
|
||||
"""Return secure devices pin."""
|
||||
return self._entity_config
|
||||
|
||||
def should_expose(self, state):
|
||||
"""Expose it all."""
|
||||
return self._should_expose is None or self._should_expose(state)
|
||||
|
||||
|
||||
BASIC_CONFIG = MockConfig()
|
||||
|
||||
DEMO_DEVICES = [{
|
||||
'id':
|
||||
|
||||
@@ -11,7 +11,7 @@ from homeassistant.components.climate.const import (
|
||||
ATTR_MIN_TEMP, ATTR_MAX_TEMP, STATE_HEAT, SUPPORT_OPERATION_MODE
|
||||
)
|
||||
from homeassistant.components.google_assistant import (
|
||||
const, trait, helpers, smart_home as sh,
|
||||
const, trait, smart_home as sh,
|
||||
EVENT_COMMAND_RECEIVED, EVENT_QUERY_RECEIVED, EVENT_SYNC_RECEIVED)
|
||||
from homeassistant.components.demo.binary_sensor import DemoBinarySensor
|
||||
from homeassistant.components.demo.cover import DemoCover
|
||||
@@ -23,9 +23,8 @@ from homeassistant.helpers import device_registry
|
||||
from tests.common import (mock_device_registry, mock_registry,
|
||||
mock_area_registry, mock_coro)
|
||||
|
||||
BASIC_CONFIG = helpers.Config(
|
||||
should_expose=lambda state: True,
|
||||
)
|
||||
from . import BASIC_CONFIG, MockConfig
|
||||
|
||||
REQ_ID = 'ff36a3cc-ec34-11e6-b1a0-64510650abcf'
|
||||
|
||||
|
||||
@@ -57,7 +56,7 @@ async def test_sync_message(hass):
|
||||
# Excluded via config
|
||||
hass.states.async_set('light.not_expose', 'on')
|
||||
|
||||
config = helpers.Config(
|
||||
config = MockConfig(
|
||||
should_expose=lambda state: state.entity_id != 'light.not_expose',
|
||||
entity_config={
|
||||
'light.demo_light': {
|
||||
@@ -145,7 +144,7 @@ async def test_sync_in_area(hass, registries):
|
||||
light.entity_id = entity.entity_id
|
||||
await light.async_update_ha_state()
|
||||
|
||||
config = helpers.Config(
|
||||
config = MockConfig(
|
||||
should_expose=lambda _: True,
|
||||
entity_config={}
|
||||
)
|
||||
|
||||
@@ -29,10 +29,8 @@ from homeassistant.const import (
|
||||
from homeassistant.core import State, DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE
|
||||
from homeassistant.util import color
|
||||
from tests.common import async_mock_service, mock_coro
|
||||
from . import BASIC_CONFIG, MockConfig
|
||||
|
||||
BASIC_CONFIG = helpers.Config(
|
||||
should_expose=lambda state: True,
|
||||
)
|
||||
|
||||
REQ_ID = 'ff36a3cc-ec34-11e6-b1a0-64510650abcf'
|
||||
|
||||
@@ -42,8 +40,7 @@ BASIC_DATA = helpers.RequestData(
|
||||
REQ_ID,
|
||||
)
|
||||
|
||||
PIN_CONFIG = helpers.Config(
|
||||
should_expose=lambda state: True,
|
||||
PIN_CONFIG = MockConfig(
|
||||
secure_devices_pin='1234'
|
||||
)
|
||||
|
||||
@@ -927,7 +924,7 @@ async def test_lock_unlock_unlock(hass):
|
||||
|
||||
# Test with 2FA override
|
||||
with patch('homeassistant.components.google_assistant.helpers'
|
||||
'.Config.should_2fa', return_value=False):
|
||||
'.AbstractConfig.should_2fa', return_value=False):
|
||||
await trt.execute(
|
||||
trait.COMMAND_LOCKUNLOCK, BASIC_DATA, {'lock': False}, {})
|
||||
assert len(calls) == 2
|
||||
|
||||
Reference in new issue
Block a user