Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ruff from 0.1.7 to 0.1.8 #192

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ updates:
versioning-strategy: "lockfile-only"
schedule:
interval: "weekly"
labels:
- "dependencies"
labels: [":robot: bot", ":game_die: dependencies"]

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
labels: [":robot: bot", ":game_die: dependencies"]
12 changes: 5 additions & 7 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
- name: ":bug: bug"
color: "b60205"
description: ""
- name: ":sparkles: custom enhancement"
color: "018786"
- name: ":warning: breaking change"
color: "b60205"
description: ""
- name: ":bulb: custom feature"
color: "03dac6"
- name: ":game_die: dependencies"
color: "0366d6"
description: ""
Expand All @@ -26,16 +24,16 @@
- name: ":speech_balloon: translation"
color: "b2a8a6"
description: ""
- name: ":sparkles: enhancement"
- name: ":wrench: enhancement"
color: "0054ca"
description: ""
- name: ":bulb: feature"
- name: ":rocket: feature"
color: "0e8a16"
description: ""
- name: ":mega: feedback"
color: "03a9f4"
description: ""
- name: ":rocket: future maybe"
- name: ":clock10: future maybe"
color: "fef2c0"
description: ""
- name: ":hatching_chick: good first issue"
Expand Down
17 changes: 6 additions & 11 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ tag-template: "v$RESOLVED_VERSION"
sort-direction: ascending
categories:
- title: "⚠ Breaking changes"
label: "breaking change"
labels: [":warning: breaking change"]
- title: "🚀 Features"
labels:
- "feature"
labels: [":rocket: feature"]
- title: "🔧 Code enhancements"
labels:
- "enhancement"
labels: [":wrench: enhancement"]
- title: "🐛 Bug Fixes"
labels:
- "fix"
- "bugfix"
- "bug"
labels: [":bug: bug"]
- title: "🈵 Translations"
label: "translation"
labels: [":speech_balloon: translation"]
- title: "📄 Documentation"
label: "documentation"
labels: [":memo: documentation"]
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
template: |
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
name: "Linting"
name: "Lint code"

on:
push:
branches: ["master", "main"]
pull_request:

jobs:
Expand Down
16 changes: 10 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ repos:
hooks:
- id: check-added-large-files
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-xml
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: no-commit-to-branch
args: ['--branch', 'main', '--branch', 'master']
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
- id: ruff format
name: ruff format
entry: poetry run ruff format
language: system
types: [python]
require_serial: true
- id: ruff
name: ruff
- id: ruff lint
name: ruff lint
entry: poetry run ruff
language: system
types: [python]
33 changes: 8 additions & 25 deletions custom_components/toyota/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Toyota integration"""
"""Toyota integration."""
from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -73,13 +73,10 @@ async def async_setup_entry( # pylint: disable=too-many-statements
except ToyotaLoginError as ex:
raise ConfigEntryAuthFailed(ex) from ex
except (httpx.ConnectTimeout, httpcore.ConnectTimeout) as ex:
raise ConfigEntryNotReady(
"Unable to connect to Toyota Connected Services"
) from ex
raise ConfigEntryNotReady("Unable to connect to Toyota Connected Services") from ex

async def async_get_vehicle_data() -> list[VehicleData]:
"""Fetch vehicle data from Toyota API."""

try:
vehicles = await asyncio.wait_for(client.get_vehicles(), 15)
vehicle_informations: list[VehicleData] = []
Expand All @@ -93,34 +90,21 @@ async def async_get_vehicle_data() -> list[VehicleData]:
False: CONF_UNIT_SYSTEM_IMPERIAL,
True: CONF_UNIT_SYSTEM_IMPERIAL_LITERS,
}
unit = (
CONF_UNIT_SYSTEM_METRIC
if vehicle_status.dashboard.is_metric
else unit_system_map[use_liters]
)
unit = CONF_UNIT_SYSTEM_METRIC if vehicle_status.dashboard.is_metric else unit_system_map[use_liters]

_LOGGER.debug(f"The car is reporting data in {unit}")
if use_liters and not vehicle_status.dashboard.is_metric:
_LOGGER.debug("Getting statistics in imperial and L/100 miles")
elif not vehicle_status.dashboard.is_metric:
_LOGGER.debug("Getting statistics in imperial and MPG")

if (
vehicle_status.is_connected_services_enabled
and vehicle_status.vin is not None
):
if vehicle_status.is_connected_services_enabled and vehicle_status.vin is not None:
# Use parallel request to get car statistics.
driving_statistics = await asyncio.gather(
client.get_driving_statistics(
vehicle_status.vin, interval="day", unit=unit
),
client.get_driving_statistics(
vehicle_status.vin, interval="isoweek", unit=unit
),
client.get_driving_statistics(vehicle_status.vin, interval="day", unit=unit),
client.get_driving_statistics(vehicle_status.vin, interval="isoweek", unit=unit),
client.get_driving_statistics(vehicle_status.vin, unit=unit),
client.get_driving_statistics(
vehicle_status.vin, interval="year", unit=unit
),
client.get_driving_statistics(vehicle_status.vin, interval="year", unit=unit),
)

vehicle_data["statistics"] = StatisticsData(
Expand Down Expand Up @@ -149,8 +133,7 @@ async def async_get_vehicle_data() -> list[VehicleData]:
httpx.ReadTimeout,
) as ex:
raise UpdateFailed(
"Update canceled! Toyota's API was too slow to respond."
" Will try again later..."
"Update canceled! Toyota's API was too slow to respond." " Will try again later..."
) from ex

coordinator = DataUpdateCoordinator(
Expand Down
23 changes: 8 additions & 15 deletions custom_components/toyota/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Binary sensor platform for Toyota integration"""
"""Binary sensor platform for Toyota integration."""


from __future__ import annotations
Expand Down Expand Up @@ -33,9 +33,7 @@ class ToyotaBinaryEntityDescriptionMixin:


@dataclass
class ToyotaBinaryEntityDescription(
BinarySensorEntityDescription, ToyotaBinaryEntityDescriptionMixin
):
class ToyotaBinaryEntityDescription(BinarySensorEntityDescription, ToyotaBinaryEntityDescriptionMixin):
"""Describes a Toyota binary entity."""


Expand Down Expand Up @@ -81,15 +79,15 @@ class ToyotaBinaryEntityDescription(
icon="mdi:car-defrost-front",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda vehicle: vehicle.hvac.front_defogger_is_on,
attributes_fn=lambda vehicle: None,
attributes_fn=lambda vehicle: None, # noqa : ARG005
),
ToyotaBinaryEntityDescription(
key="rear_defogger",
translation_key="rear_defogger",
icon="mdi:car-defrost-rear",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda vehicle: vehicle.hvac.rear_defogger_is_on,
attributes_fn=lambda vehicle: None,
attributes_fn=lambda vehicle: None, # noqa : ARG005
),
)

Expand All @@ -112,8 +110,7 @@ class ToyotaBinaryEntityDescription(
icon="mdi:car-door",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.WINDOW,
value_fn=lambda vehicle: vehicle.sensors.windows.passenger_seat.state
!= "close",
value_fn=lambda vehicle: vehicle.sensors.windows.passenger_seat.state != "close",
attributes_fn=lambda vehicle: {
WARNING: vehicle.sensors.windows.passenger_seat.warning,
LAST_UPDATED: vehicle.sensors.last_updated,
Expand All @@ -137,8 +134,7 @@ class ToyotaBinaryEntityDescription(
icon="mdi:car-door",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.WINDOW,
value_fn=lambda vehicle: vehicle.sensors.windows.rightrear_seat.state
!= "close",
value_fn=lambda vehicle: vehicle.sensors.windows.rightrear_seat.state != "close",
attributes_fn=lambda vehicle: {
WARNING: vehicle.sensors.windows.rightrear_seat.warning,
LAST_UPDATED: vehicle.sensors.last_updated,
Expand Down Expand Up @@ -309,16 +305,13 @@ class ToyotaBinaryEntityDescription(
)


async def async_setup_entry(
async def async_setup_entry( # noqa: PLR0912
hass: HomeAssistant,
entry: ConfigEntry,
async_add_devices: AddEntitiesCallback,
) -> None:
"""Set up the binary sensor platform."""

coordinator: DataUpdateCoordinator[list[VehicleData]] = hass.data[DOMAIN][
entry.entry_id
]
coordinator: DataUpdateCoordinator[list[VehicleData]] = hass.data[DOMAIN][entry.entry_id]

binary_sensors: list[ToyotaBinarySensor] = []
for index, _ in enumerate(coordinator.data):
Expand Down
17 changes: 5 additions & 12 deletions custom_components/toyota/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ async def async_step_user(self, user_input=None) -> FlowResult:
errors["base"] = "unknown"
_LOGGER.error("An unknown error occurred during login request: %s", ex)
else:
return self.async_create_entry(
title=user_input[CONF_EMAIL], data=user_input
)
return self.async_create_entry(title=user_input[CONF_EMAIL], data=user_input)

return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA, errors=errors)

@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get async options flow."""
return ToyotaOptionsFlowHandler(config_entry)


Expand All @@ -82,19 +79,15 @@ async def async_step_init(self, user_input=None) -> FlowResult:
"""Manage the options."""
if user_input is not None:
self.options.update(user_input)
return self.async_create_entry(
title=self.config_entry.data.get(CONF_EMAIL), data=self.options
)
return self.async_create_entry(title=self.config_entry.data.get(CONF_EMAIL), data=self.options)

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Optional(
CONF_USE_LITERS_PER_100_MILES,
default=self.config_entry.options.get(
CONF_USE_LITERS_PER_100_MILES, False
),
default=self.config_entry.options.get(CONF_USE_LITERS_PER_100_MILES, False),
): bool,
}
),
Expand Down
9 changes: 3 additions & 6 deletions custom_components/toyota/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Device tracker platform for Toyota Connected Services"""
"""Device tracker platform for Toyota Connected Services."""

from typing import Optional

Expand Down Expand Up @@ -27,9 +27,7 @@ async def async_setup_entry(
async_add_devices: AddEntitiesCallback,
) -> None:
"""Set up the Toyota Connected Services tracker from config entry."""
coordinator: DataUpdateCoordinator[list[VehicleData]] = hass.data[DOMAIN][
entry.entry_id
]
coordinator: DataUpdateCoordinator[list[VehicleData]] = hass.data[DOMAIN][entry.entry_id]

async_add_devices(
ToyotaParkingTracker(
Expand All @@ -39,8 +37,7 @@ async def async_setup_entry(
description=PARKING_TRACKER_DESCRIPTION,
)
for index, vehicle in enumerate(coordinator.data)
if vehicle["data"].is_connected_services_enabled
and vehicle["data"].parkinglocation
if vehicle["data"].is_connected_services_enabled and vehicle["data"].parkinglocation
)


Expand Down
2 changes: 1 addition & 1 deletion custom_components/toyota/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Custom coordinator entity base classes for Toyota Connected Services integration"""
"""Custom coordinator entity base classes for Toyota Connected Services integration."""
from __future__ import annotations

from homeassistant.core import callback
Expand Down
Loading