예제 #1
0
def mock_nexrad_data():
    data = load_fixture("station.xml")
    with patch(
        "custom_components.nwsradar.Nexrad._get_data", return_value=data
    ) as mock_nexrad_data, patch(
        "pynwsradar.nexrad.Layer.update_image"
    ) as mock_layer_update, patch(
        "pynwsradar.nexrad.Layer.image", return_value=b"test"
    ) as mock_layer_image:
        yield mock_nexrad_data, mock_layer_update, mock_layer_image
예제 #2
0
    def __init__(self, mock) -> None:
        """Create a mocked client."""
        self.xmppclient = MagicMock()

        self.xmppclient.connected_event = asyncio.Event()
        self.xmppclient.message_event = asyncio.Event()

        self.serial_number = None
        self.callback = None

        self.mock = mock

        self.data = json.loads(load_fixture("nefit_data.json"))
예제 #3
0
async def create_unavailable_vehicle_proxy(
    hass: HomeAssistant, vehicle_type: str
) -> RenaultVehicleProxy:
    """Create a vehicle proxy for testing unavailable entities."""
    mock_vehicle = MOCK_VEHICLES[vehicle_type]

    vehicles_response: models.KamereonVehiclesResponse = (
        schemas.KamereonVehiclesResponseSchema.loads(
            load_fixture(f"vehicle_{vehicle_type}.json")
        )
    )
    vehicle_details = vehicles_response.vehicleLinks[0].vehicleDetails
    vehicle = RenaultVehicle(
        vehicles_response.accountId,
        vehicle_details.vin,
        websession=aiohttp_client.async_get_clientsession(hass),
    )

    invalid_upstream_exception = exceptions.InvalidUpstreamException(
        "err.tech.500",
        "Invalid response from the upstream server (The request sent to the GDC is erroneous) ; 502 Bad Gateway",
    )

    vehicle_proxy = RenaultVehicleProxy(
        hass, vehicle, vehicle_details, timedelta(seconds=300), False
    )
    with patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.endpoint_available",
        side_effect=mock_vehicle["endpoints_available"],
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_cockpit",
        side_effect=invalid_upstream_exception,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_hvac_status",
        side_effect=invalid_upstream_exception,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_battery_status",
        side_effect=invalid_upstream_exception,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_charge_mode",
        side_effect=invalid_upstream_exception,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_location",
        side_effect=invalid_upstream_exception,
    ):
        await vehicle_proxy.async_initialise()
    return vehicle_proxy
예제 #4
0
파일: util.py 프로젝트: ehendrix23/hass_myq
async def async_init_integration(
    hass: HomeAssistant,
    skip_setup: bool = False,
) -> MockConfigEntry:
    """Set up the myq integration in Home Assistant."""

    devices_fixture = "devices.json"
    devices_json = load_fixture(devices_fixture)
    devices_dict = json.loads(devices_json)

    def _handle_mock_api_oauth_authenticate():
        return 1234, 1800

    def _handle_mock_api_request(method, returns, url, **kwargs):
        _LOGGER.debug("URL: %s", url)
        if url == ACCOUNTS_ENDPOINT:
            _LOGGER.debug("Accounts")
            return None, {"accounts": [{"id": 1, "name": "mock"}]}
        if url == DEVICES_ENDPOINT.format(account_id=1):
            _LOGGER.debug("Devices")
            return None, devices_dict
        _LOGGER.debug("Something else")
        return None, {}

    # Added patch to resolve from root as currently HASS picks up the myq core component and not
    # the custom component. This can be removed once myq is removed from the core.
    with patch(
            "pymyq.api.API._oauth_authenticate",
            side_effect=_handle_mock_api_oauth_authenticate,
    ), patch("pymyq.api.API.request",
             side_effect=_handle_mock_api_request), patch(
                 "homeassistant.loader.Integration.resolve_from_root",
                 return_value=None):
        entry = MockConfigEntry(domain=DOMAIN,
                                data={
                                    CONF_USERNAME: "******",
                                    CONF_PASSWORD: "******"
                                })
        entry.add_to_hass(hass)

        if not skip_setup:
            await hass.config_entries.async_setup(entry.entry_id)
            await hass.async_block_till_done()

    return entry
예제 #5
0
async def create_vehicle_proxy(
    hass: HomeAssistant, vehicle_type: str
) -> RenaultVehicleProxy:
    """Create a vehicle proxy for testing."""
    mock_vehicle = MOCK_VEHICLES[vehicle_type]
    mock_get_cockpit = schemas.KamereonVehicleDataResponseSchema.loads(
        load_fixture(mock_vehicle["endpoints"]["cockpit"])
        if "cockpit" in mock_vehicle["endpoints"]
        else "{}"
    ).get_attributes(schemas.KamereonVehicleCockpitDataSchema)
    mock_get_hvac_status = schemas.KamereonVehicleDataResponseSchema.loads(
        load_fixture(mock_vehicle["endpoints"]["hvac_status"])
        if "hvac_status" in mock_vehicle["endpoints"]
        else "{}"
    ).get_attributes(schemas.KamereonVehicleHvacStatusDataSchema)
    mock_get_battery_status = schemas.KamereonVehicleDataResponseSchema.loads(
        load_fixture(mock_vehicle["endpoints"]["battery_status"])
        if "battery_status" in mock_vehicle["endpoints"]
        else "{}"
    ).get_attributes(schemas.KamereonVehicleBatteryStatusDataSchema)
    mock_get_charge_mode = schemas.KamereonVehicleDataResponseSchema.loads(
        load_fixture(mock_vehicle["endpoints"]["charge_mode"])
        if "charge_mode" in mock_vehicle["endpoints"]
        else "{}"
    ).get_attributes(schemas.KamereonVehicleChargeModeDataSchema)
    mock_get_location = schemas.KamereonVehicleDataResponseSchema.loads(
        load_fixture(mock_vehicle["endpoints"]["location"])
        if "location" in mock_vehicle["endpoints"]
        else "{}"
    ).get_attributes(schemas.KamereonVehicleLocationDataSchema)

    vehicles_response: models.KamereonVehiclesResponse = (
        schemas.KamereonVehiclesResponseSchema.loads(
            load_fixture(f"vehicle_{vehicle_type}.json")
        )
    )
    vehicle_details = vehicles_response.vehicleLinks[0].vehicleDetails
    vehicle = RenaultVehicle(
        vehicles_response.accountId,
        vehicle_details.vin,
        websession=aiohttp_client.async_get_clientsession(hass),
    )

    vehicle_proxy = RenaultVehicleProxy(
        hass, vehicle, vehicle_details, timedelta(seconds=300), False
    )
    with patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.endpoint_available",
        side_effect=mock_vehicle["endpoints_available"],
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_cockpit",
        return_value=mock_get_cockpit,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_hvac_status",
        return_value=mock_get_hvac_status,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_battery_status",
        return_value=mock_get_battery_status,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_charge_mode",
        return_value=mock_get_charge_mode,
    ), patch(
        "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_location",
        return_value=mock_get_location,
    ):
        await vehicle_proxy.async_initialise()
    return vehicle_proxy