hass-core/tests/components/vesync/common.py
Chuck Deal 09d0128601
Add diagnostics to VeSync (#86350)
* Add diagnostics to VeSync

* Create unit tests for diagnostics and init

* Improved diagnostic test coverage

* Peer review fixes

* Fixed Peer Review comments

* Updated based on Peer Review

* Additional diagnostic redactions

* Removed account_id from diagnostic output
2023-02-28 22:12:48 -05:00

72 lines
2.6 KiB
Python

"""Common methods used across tests for VeSync."""
import json
from tests.common import load_fixture
def call_api_side_effect__no_devices(*args, **kwargs):
"""Build a side_effects method for the Helpers.call_api method."""
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
return (
json.loads(
load_fixture("vesync_api_call__devices__no_devices.json", "vesync")
),
200,
)
else:
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
def call_api_side_effect__single_humidifier(*args, **kwargs):
"""Build a side_effects method for the Helpers.call_api method."""
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
return (
json.loads(
load_fixture(
"vesync_api_call__devices__single_humidifier.json", "vesync"
)
),
200,
)
elif args[0] == "/cloud/v2/deviceManaged/bypassV2" and kwargs["method"] == "post":
return (
json.loads(
load_fixture(
"vesync_api_call__device_details__single_humidifier.json", "vesync"
)
),
200,
)
else:
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
def call_api_side_effect__single_fan(*args, **kwargs):
"""Build a side_effects method for the Helpers.call_api method."""
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
return (
json.loads(
load_fixture("vesync_api_call__devices__single_fan.json", "vesync")
),
200,
)
elif (
args[0] == "/131airPurifier/v1/device/deviceDetail"
and kwargs["method"] == "post"
):
return (
json.loads(
load_fixture(
"vesync_api_call__device_details__single_fan.json", "vesync"
)
),
200,
)
else:
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")