Add missing hass type hint in august tests (#124062)
This commit is contained in:
parent
ce2ffde22e
commit
135ebaafa0
2 changed files with 31 additions and 25 deletions
|
@ -18,6 +18,7 @@ from yalexs.activity import (
|
||||||
ACTIVITY_ACTIONS_LOCK_OPERATION,
|
ACTIVITY_ACTIONS_LOCK_OPERATION,
|
||||||
SOURCE_LOCK_OPERATE,
|
SOURCE_LOCK_OPERATE,
|
||||||
SOURCE_LOG,
|
SOURCE_LOG,
|
||||||
|
Activity,
|
||||||
BridgeOperationActivity,
|
BridgeOperationActivity,
|
||||||
DoorbellDingActivity,
|
DoorbellDingActivity,
|
||||||
DoorbellMotionActivity,
|
DoorbellMotionActivity,
|
||||||
|
@ -65,8 +66,8 @@ def _timetoken():
|
||||||
@patch("yalexs.manager.gateway.ApiAsync")
|
@patch("yalexs.manager.gateway.ApiAsync")
|
||||||
@patch("yalexs.manager.gateway.AuthenticatorAsync.async_authenticate")
|
@patch("yalexs.manager.gateway.AuthenticatorAsync.async_authenticate")
|
||||||
async def _mock_setup_august(
|
async def _mock_setup_august(
|
||||||
hass, api_instance, pubnub_mock, authenticate_mock, api_mock, brand
|
hass: HomeAssistant, api_instance, pubnub_mock, authenticate_mock, api_mock, brand
|
||||||
):
|
) -> MockConfigEntry:
|
||||||
"""Set up august integration."""
|
"""Set up august integration."""
|
||||||
authenticate_mock.side_effect = MagicMock(
|
authenticate_mock.side_effect = MagicMock(
|
||||||
return_value=_mock_august_authentication(
|
return_value=_mock_august_authentication(
|
||||||
|
@ -107,13 +108,13 @@ async def _create_august_with_devices(
|
||||||
|
|
||||||
|
|
||||||
async def _create_august_api_with_devices(
|
async def _create_august_api_with_devices(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
devices,
|
devices: Iterable[LockDetail | DoorbellDetail],
|
||||||
api_call_side_effects=None,
|
api_call_side_effects: dict[str, Any] | None = None,
|
||||||
activities=None,
|
activities: list[Any] | None = None,
|
||||||
pubnub=None,
|
pubnub: AugustPubNub | None = None,
|
||||||
brand=Brand.AUGUST,
|
brand: Brand = Brand.AUGUST,
|
||||||
):
|
) -> tuple[MockConfigEntry, MagicMock]:
|
||||||
if api_call_side_effects is None:
|
if api_call_side_effects is None:
|
||||||
api_call_side_effects = {}
|
api_call_side_effects = {}
|
||||||
if pubnub is None:
|
if pubnub is None:
|
||||||
|
@ -215,7 +216,10 @@ async def _create_august_api_with_devices(
|
||||||
|
|
||||||
|
|
||||||
async def _mock_setup_august_with_api_side_effects(
|
async def _mock_setup_august_with_api_side_effects(
|
||||||
hass, api_call_side_effects, pubnub, brand=Brand.AUGUST
|
hass: HomeAssistant,
|
||||||
|
api_call_side_effects: dict[str, Any],
|
||||||
|
pubnub: AugustPubNub,
|
||||||
|
brand: Brand = Brand.AUGUST,
|
||||||
):
|
):
|
||||||
api_instance = MagicMock(name="Api", brand=brand)
|
api_instance = MagicMock(name="Api", brand=brand)
|
||||||
|
|
||||||
|
@ -335,19 +339,21 @@ def _mock_august_lock_data(lockid="mocklockid1", houseid="mockhouseid1"):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def _mock_operative_august_lock_detail(hass):
|
async def _mock_operative_august_lock_detail(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.online.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.online.json")
|
||||||
|
|
||||||
|
|
||||||
async def _mock_lock_with_offline_key(hass):
|
async def _mock_lock_with_offline_key(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.online_with_keys.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.online_with_keys.json")
|
||||||
|
|
||||||
|
|
||||||
async def _mock_inoperative_august_lock_detail(hass):
|
async def _mock_inoperative_august_lock_detail(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.offline.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.offline.json")
|
||||||
|
|
||||||
|
|
||||||
async def _mock_activities_from_fixture(hass, path):
|
async def _mock_activities_from_fixture(
|
||||||
|
hass: HomeAssistant, path: str
|
||||||
|
) -> list[Activity]:
|
||||||
json_dict = await _load_json_fixture(hass, path)
|
json_dict = await _load_json_fixture(hass, path)
|
||||||
activities = []
|
activities = []
|
||||||
for activity_json in json_dict:
|
for activity_json in json_dict:
|
||||||
|
@ -358,32 +364,32 @@ async def _mock_activities_from_fixture(hass, path):
|
||||||
return activities
|
return activities
|
||||||
|
|
||||||
|
|
||||||
async def _mock_lock_from_fixture(hass, path):
|
async def _mock_lock_from_fixture(hass: HomeAssistant, path: str) -> LockDetail:
|
||||||
json_dict = await _load_json_fixture(hass, path)
|
json_dict = await _load_json_fixture(hass, path)
|
||||||
return LockDetail(json_dict)
|
return LockDetail(json_dict)
|
||||||
|
|
||||||
|
|
||||||
async def _mock_doorbell_from_fixture(hass, path):
|
async def _mock_doorbell_from_fixture(hass: HomeAssistant, path: str) -> DoorbellDetail:
|
||||||
json_dict = await _load_json_fixture(hass, path)
|
json_dict = await _load_json_fixture(hass, path)
|
||||||
return DoorbellDetail(json_dict)
|
return DoorbellDetail(json_dict)
|
||||||
|
|
||||||
|
|
||||||
async def _load_json_fixture(hass, path):
|
async def _load_json_fixture(hass: HomeAssistant, path: str) -> Any:
|
||||||
fixture = await hass.async_add_executor_job(
|
fixture = await hass.async_add_executor_job(
|
||||||
load_fixture, os.path.join("august", path)
|
load_fixture, os.path.join("august", path)
|
||||||
)
|
)
|
||||||
return json.loads(fixture)
|
return json.loads(fixture)
|
||||||
|
|
||||||
|
|
||||||
async def _mock_doorsense_enabled_august_lock_detail(hass):
|
async def _mock_doorsense_enabled_august_lock_detail(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.online_with_doorsense.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.online_with_doorsense.json")
|
||||||
|
|
||||||
|
|
||||||
async def _mock_doorsense_missing_august_lock_detail(hass):
|
async def _mock_doorsense_missing_august_lock_detail(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.online_missing_doorsense.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.online_missing_doorsense.json")
|
||||||
|
|
||||||
|
|
||||||
async def _mock_lock_with_unlatch(hass):
|
async def _mock_lock_with_unlatch(hass: HomeAssistant) -> LockDetail:
|
||||||
return await _mock_lock_from_fixture(hass, "get_lock.online_with_unlatch.json")
|
return await _mock_lock_from_fixture(hass, "get_lock.online_with_unlatch.json")
|
||||||
|
|
||||||
|
|
||||||
|
@ -411,7 +417,7 @@ def _mock_door_operation_activity(lock, action, offset):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _activity_from_dict(activity_dict):
|
def _activity_from_dict(activity_dict: dict[str, Any]) -> Activity | None:
|
||||||
action = activity_dict.get("action")
|
action = activity_dict.get("action")
|
||||||
|
|
||||||
activity_dict["dateTime"] = time.time() * 1000
|
activity_dict["dateTime"] = time.time() * 1000
|
||||||
|
|
|
@ -22,14 +22,14 @@ async def test_refresh_access_token(hass: HomeAssistant) -> None:
|
||||||
@patch("yalexs.manager.gateway.AuthenticatorAsync.should_refresh")
|
@patch("yalexs.manager.gateway.AuthenticatorAsync.should_refresh")
|
||||||
@patch("yalexs.manager.gateway.AuthenticatorAsync.async_refresh_access_token")
|
@patch("yalexs.manager.gateway.AuthenticatorAsync.async_refresh_access_token")
|
||||||
async def _patched_refresh_access_token(
|
async def _patched_refresh_access_token(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
new_token,
|
new_token: str,
|
||||||
new_token_expire_time,
|
new_token_expire_time: int,
|
||||||
refresh_access_token_mock,
|
refresh_access_token_mock,
|
||||||
should_refresh_mock,
|
should_refresh_mock,
|
||||||
authenticate_mock,
|
authenticate_mock,
|
||||||
async_get_operable_locks_mock,
|
async_get_operable_locks_mock,
|
||||||
):
|
) -> None:
|
||||||
authenticate_mock.side_effect = MagicMock(
|
authenticate_mock.side_effect = MagicMock(
|
||||||
return_value=_mock_august_authentication(
|
return_value=_mock_august_authentication(
|
||||||
"original_token", 1234, AuthenticationState.AUTHENTICATED
|
"original_token", 1234, AuthenticationState.AUTHENTICATED
|
||||||
|
|
Loading…
Add table
Reference in a new issue