示例#1
0
def create_mock_bridge(hass):
    """Create a mock Hue bridge."""
    bridge = Mock(
        hass=hass,
        available=True,
        authorized=True,
        allow_unreachable=False,
        allow_groups=False,
        api=Mock(),
        reset_jobs=[],
        spec=hue.HueBridge,
    )
    bridge.sensor_manager = hue_sensor_base.SensorManager(bridge)
    bridge.mock_requests = []
    # We're using a deque so we can schedule multiple responses
    # and also means that `popleft()` will blow up if we get more updates
    # than expected.
    bridge.mock_sensor_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        bridge.mock_requests.append(kwargs)

        if path == "sensors":
            return bridge.mock_sensor_responses.popleft()
        return None

    async def async_request_call(coro):
        await coro

    bridge.async_request_call = async_request_call
    bridge.api.config.apiversion = "9.9.9"
    bridge.api.sensors = Sensors({}, mock_request)
    return bridge
示例#2
0
def mock_api(hass):
    """Mock the Hue api."""
    api = Mock(initialize=AsyncMock())
    api.mock_requests = []
    api.mock_light_responses = deque()
    api.mock_group_responses = deque()
    api.mock_sensor_responses = deque()
    api.mock_scene_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        api.mock_requests.append(kwargs)

        if path == "lights":
            return api.mock_light_responses.popleft()
        if path == "groups":
            return api.mock_group_responses.popleft()
        if path == "sensors":
            return api.mock_sensor_responses.popleft()
        if path == "scenes":
            return api.mock_scene_responses.popleft()
        return None

    api.config.apiversion = "9.9.9"
    api.lights = Lights({}, mock_request)
    api.groups = Groups({}, mock_request)
    api.sensors = Sensors({}, mock_request)
    api.scenes = Scenes({}, mock_request)
    return api
def create_mock_bridge(hass):
    """Create a mock Hue bridge."""
    bridge = Mock(
        hass=hass,
        available=True,
        authorized=True,
        allow_unreachable=False,
        allow_groups=False,
        api=Mock(),
        reset_jobs=[],
        spec=hue.HueBridge,
    )
    bridge.sensor_manager = hue_sensor_base.SensorManager(bridge)
    bridge.mock_requests = []

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        bridge.mock_requests.append(kwargs)
        return {}

    async def async_request_call(task):
        await task()

    bridge.async_request_call = async_request_call
    bridge.api.config.apiversion = "9.9.9"
    bridge.api.lights = Lights({}, mock_request)
    bridge.api.groups = Groups({}, mock_request)
    bridge.api.sensors = Sensors({}, mock_request)
    bridge.api.scenes = Scenes({}, mock_request)
    return bridge
示例#4
0
def mock_bridge(hass):
    """Mock a Hue bridge."""
    bridge = Mock(available=True,
                  allow_unreachable=False,
                  allow_groups=False,
                  api=Mock(),
                  spec=hue.HueBridge)
    bridge.mock_requests = []
    # We're using a deque so we can schedule multiple responses
    # and also means that `popleft()` will blow up if we get more updates
    # than expected.
    bridge.mock_sensor_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs['method'] = method
        kwargs['path'] = path
        bridge.mock_requests.append(kwargs)

        if path == 'sensors':
            return bridge.mock_sensor_responses.popleft()
        return None

    bridge.api.config.apiversion = '9.9.9'
    bridge.api.sensors = Sensors({}, mock_request)

    return bridge
示例#5
0
def create_mock_api(hass):
    """Create a mock API."""
    api = Mock(initialize=AsyncMock())
    api.mock_requests = []
    api.mock_light_responses = deque()
    api.mock_group_responses = deque()
    api.mock_sensor_responses = deque()
    api.mock_scene_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        api.mock_requests.append(kwargs)

        if path == "lights":
            return api.mock_light_responses.popleft()
        if path == "groups":
            return api.mock_group_responses.popleft()
        if path == "sensors":
            return api.mock_sensor_responses.popleft()
        if path == "scenes":
            return api.mock_scene_responses.popleft()
        return None

    logger = logging.getLogger(__name__)

    api.config.apiversion = "9.9.9"
    api.lights = Lights(logger, {}, mock_request)
    api.groups = Groups(logger, {}, mock_request)
    api.sensors = Sensors(logger, {}, mock_request)
    api.scenes = Scenes(logger, {}, mock_request)
    return api
示例#6
0
def create_mock_api(hass):
    """Create a mock API."""
    api = Mock(initialize=AsyncMock())
    api.mock_requests = []
    api.mock_light_responses = deque()
    api.mock_group_responses = deque()
    api.mock_sensor_responses = deque()
    api.mock_scene_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        api.mock_requests.append(kwargs)

        if path == "lights":
            return api.mock_light_responses.popleft()
        if path == "groups":
            return api.mock_group_responses.popleft()
        if path == "sensors":
            return api.mock_sensor_responses.popleft()
        if path == "scenes":
            return api.mock_scene_responses.popleft()
        return None

    logger = logging.getLogger(__name__)

    api.config = Mock(
        bridgeid="ff:ff:ff:ff:ff:ff",
        mac="aa:bb:cc:dd:ee:ff",
        modelid="BSB002",
        apiversion="9.9.9",
        swversion="1935144040",
    )
    api.config.name = "Home"

    api.lights = Lights(logger, {}, [], mock_request)
    api.groups = Groups(logger, {}, [], mock_request)
    api.sensors = Sensors(logger, {}, [], mock_request)
    api.scenes = Scenes(logger, {}, [], mock_request)
    return api