Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and G-Two committed Feb 27, 2024
1 parent 7946151 commit 77f6836
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 145 deletions.
1 change: 1 addition & 0 deletions custom_components/subaru/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Subaru integration."""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru binary sensors."""

from __future__ import annotations

from datetime import datetime
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru buttons."""

from __future__ import annotations

import logging
Expand Down
7 changes: 4 additions & 3 deletions custom_components/subaru/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Subaru integration."""

from __future__ import annotations

from datetime import datetime
Expand Down Expand Up @@ -86,9 +87,9 @@ async def async_step_user(
): str,
vol.Required(
CONF_COUNTRY,
default=user_input.get(CONF_COUNTRY)
if user_input
else COUNTRY_USA,
default=(
user_input.get(CONF_COUNTRY) if user_input else COUNTRY_USA
),
): vol.In([COUNTRY_CAN, COUNTRY_USA]),
}
),
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for the Subaru integration."""

import subarulink.const as sc

from homeassistant.const import Platform
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common device information for a vehicle."""

from __future__ import annotations

from homeassistant.helpers.entity import DeviceInfo
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru device tracker."""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Diagnostics for the Subaru integration."""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru door locks."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/migrate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Migrate entity unique_ids."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Enums for Subaru integration config options."""

from __future__ import annotations

from enum import Enum
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/remote_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Remote vehicle services for Subaru integration."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru selectors."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/subaru/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Subaru sensors."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions tests/api_responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sample API response data for tests."""

from datetime import datetime, timezone

from custom_components.subaru.const import (
Expand Down
110 changes: 63 additions & 47 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common functions needed to setup tests for Subaru component."""

from datetime import timedelta
from unittest.mock import patch

Expand Down Expand Up @@ -120,53 +121,68 @@ async def setup_subaru_config_entry(
fetch_effect=None,
):
"""Run async_setup with API mocks in place."""
with patch(
MOCK_API_CONNECT,
return_value=connect_effect is None,
side_effect=connect_effect,
), patch(
MOCK_API_GET_VEHICLES,
return_value=vehicle_list,
), patch(
MOCK_API_VIN_TO_NAME,
return_value=vehicle_data[VEHICLE_NAME],
), patch(
MOCK_API_GET_API_GEN,
return_value=vehicle_data[VEHICLE_API_GEN],
), patch(
MOCK_API_GET_MODEL_NAME,
return_value=vehicle_data[VEHICLE_MODEL_NAME],
), patch(
MOCK_API_GET_MODEL_YEAR,
return_value=vehicle_data[VEHICLE_MODEL_YEAR],
), patch(
MOCK_API_GET_EV_STATUS,
return_value=vehicle_data[VEHICLE_HAS_EV],
), patch(
MOCK_API_HAS_POWER_WINDOWS,
return_value=vehicle_data[VEHICLE_HAS_POWER_WINDOWS],
), patch(
MOCK_API_HAS_SUNROOF,
return_value=vehicle_data[VEHICLE_HAS_SUNROOF],
), patch(
MOCK_API_GET_RES_STATUS,
return_value=vehicle_data[VEHICLE_HAS_REMOTE_START],
), patch(
MOCK_API_GET_REMOTE_STATUS,
return_value=vehicle_data[VEHICLE_HAS_REMOTE_SERVICE],
), patch(
MOCK_API_GET_SAFETY_STATUS,
return_value=vehicle_data[VEHICLE_HAS_SAFETY_SERVICE],
), patch(
MOCK_API_GET_SUBSCRIPTION_STATUS,
return_value=True,
), patch(
MOCK_API_GET_DATA,
return_value=vehicle_status,
), patch(
MOCK_API_UPDATE,
), patch(
MOCK_API_FETCH, side_effect=fetch_effect
with (
patch(
MOCK_API_CONNECT,
return_value=connect_effect is None,
side_effect=connect_effect,
),
patch(
MOCK_API_GET_VEHICLES,
return_value=vehicle_list,
),
patch(
MOCK_API_VIN_TO_NAME,
return_value=vehicle_data[VEHICLE_NAME],
),
patch(
MOCK_API_GET_API_GEN,
return_value=vehicle_data[VEHICLE_API_GEN],
),
patch(
MOCK_API_GET_MODEL_NAME,
return_value=vehicle_data[VEHICLE_MODEL_NAME],
),
patch(
MOCK_API_GET_MODEL_YEAR,
return_value=vehicle_data[VEHICLE_MODEL_YEAR],
),
patch(
MOCK_API_GET_EV_STATUS,
return_value=vehicle_data[VEHICLE_HAS_EV],
),
patch(
MOCK_API_HAS_POWER_WINDOWS,
return_value=vehicle_data[VEHICLE_HAS_POWER_WINDOWS],
),
patch(
MOCK_API_HAS_SUNROOF,
return_value=vehicle_data[VEHICLE_HAS_SUNROOF],
),
patch(
MOCK_API_GET_RES_STATUS,
return_value=vehicle_data[VEHICLE_HAS_REMOTE_START],
),
patch(
MOCK_API_GET_REMOTE_STATUS,
return_value=vehicle_data[VEHICLE_HAS_REMOTE_SERVICE],
),
patch(
MOCK_API_GET_SAFETY_STATUS,
return_value=vehicle_data[VEHICLE_HAS_SAFETY_SERVICE],
),
patch(
MOCK_API_GET_SUBSCRIPTION_STATUS,
return_value=True,
),
patch(
MOCK_API_GET_DATA,
return_value=vehicle_status,
),
patch(
MOCK_API_UPDATE,
),
patch(MOCK_API_FETCH, side_effect=fetch_effect),
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
Expand Down
12 changes: 7 additions & 5 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Subaru binary sensors."""

from copy import deepcopy
from unittest.mock import patch

Expand Down Expand Up @@ -55,8 +56,9 @@ async def test_binary_sensors_missing_field(hass, ev_entry):
missing_field_set = deepcopy(VEHICLE_STATUS_EV)
missing_field_set[VEHICLE_STATUS].pop(DOOR_ENGINE_HOOD_POSITION)

with patch(MOCK_API_FETCH), patch(
MOCK_API_GET_DATA, return_value=missing_field_set
with (
patch(MOCK_API_FETCH),
patch(MOCK_API_GET_DATA, return_value=missing_field_set),
):
advance_time(hass, FETCH_INTERVAL)
await hass.async_block_till_done()
Expand Down Expand Up @@ -116,9 +118,9 @@ def _assert_data(hass, expected_state):
sensor_list.extend(API_GEN_2_BINARY_SENSORS)
expected_states = {}
for item in sensor_list:
expected_states[
f"binary_sensor.{slugify(f'{VEHICLE_NAME} {item.name}')}"
] = expected_state[item.key]
expected_states[f"binary_sensor.{slugify(f'{VEHICLE_NAME} {item.name}')}"] = (
expected_state[item.key]
)

for sensor, state in expected_states.items():
actual = hass.states.get(sensor)
Expand Down
30 changes: 18 additions & 12 deletions tests/test_button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Subaru buttons."""

from unittest.mock import patch

from pytest import raises
Expand Down Expand Up @@ -33,9 +34,10 @@ async def test_device_exists(hass, ev_entry):

async def test_button_with_fetch(hass, ev_entry):
"""Test subaru button function."""
with patch(MOCK_API_REMOTE_START) as mock_remote_start, patch(
MOCK_API_FETCH
) as mock_fetch:
with (
patch(MOCK_API_REMOTE_START) as mock_remote_start,
patch(MOCK_API_FETCH) as mock_fetch,
):
await hass.services.async_call(
BUTTON_DOMAIN, "press", {ATTR_ENTITY_ID: REMOTE_START_BUTTON}, blocking=True
)
Expand All @@ -60,9 +62,11 @@ async def test_button_without_fetch(hass, ev_entry):

async def test_button_update(hass, ev_entry):
"""Test subaru fetch button function."""
with patch(MOCK_API_FETCH), patch(
MOCK_API_GET_DATA, return_value=VEHICLE_STATUS_EV
), patch(MOCK_API_UPDATE, return_value=True) as mock_update:
with (
patch(MOCK_API_FETCH),
patch(MOCK_API_GET_DATA, return_value=VEHICLE_STATUS_EV),
patch(MOCK_API_UPDATE, return_value=True) as mock_update,
):
await hass.services.async_call(
BUTTON_DOMAIN,
"press",
Expand All @@ -88,9 +92,10 @@ async def test_button_fetch(hass, ev_entry):

async def test_button_remote_start(hass, ev_entry):
"""Test subaru remote start button function."""
with patch(MOCK_API_REMOTE_START) as mock_remote_start, patch(
MOCK_API_FETCH
) as mock_fetch:
with (
patch(MOCK_API_REMOTE_START) as mock_remote_start,
patch(MOCK_API_FETCH) as mock_fetch,
):
await hass.services.async_call(
BUTTON_DOMAIN,
"press",
Expand All @@ -104,9 +109,10 @@ async def test_button_remote_start(hass, ev_entry):

async def test_button_remote_start_failed(hass, ev_entry):
"""Test subaru remote start button function."""
with patch(MOCK_API_REMOTE_START, return_value=False) as mock_remote_start, patch(
MOCK_API_FETCH
) as mock_fetch:
with (
patch(MOCK_API_REMOTE_START, return_value=False) as mock_remote_start,
patch(MOCK_API_FETCH) as mock_fetch,
):
with raises(HomeAssistantError):
await hass.services.async_call(
BUTTON_DOMAIN,
Expand Down
Loading

0 comments on commit 77f6836

Please sign in to comment.