Skip to content

Commit

Permalink
fix: pre-commit guidelines, step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorzin committed Nov 15, 2024
1 parent 28c2a94 commit 44f6fc3
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions custom_components/aliexpress_openplatform/sensor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""Create and add sensors to Home Assistant."""

from __future__ import annotations

from typing import TYPE_CHECKING
from datetime import datetime, timedelta, timezone
import logging

from aliexpress_api import AliexpressApi, models

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, DataUpdateCoordinator, UpdateFailed,
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from homeassistant.core import HomeAssistant

Check failure on line 17 in custom_components/aliexpress_openplatform/sensor.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (TCH001)

custom_components/aliexpress_openplatform/sensor.py:17:32: TCH001 Move application import `homeassistant.core.HomeAssistant` into a type-checking block
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check failure on line 18 in custom_components/aliexpress_openplatform/sensor.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (TCH001)

custom_components/aliexpress_openplatform/sensor.py:18:51: TCH001 Move application import `homeassistant.helpers.entity_platform.AddEntitiesCallback` into a type-checking block
from typing import TYPE_CHECKING
from .const import DOMAIN, CONF_APPKEY, CONF_APPSECRET

if TYPE_CHECKING:

Check failure on line 21 in custom_components/aliexpress_openplatform/sensor.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (I001)

custom_components/aliexpress_openplatform/sensor.py:3:1: I001 Import block is un-sorted or un-formatted
Expand Down Expand Up @@ -77,24 +82,23 @@ async def _async_update_data(self) -> dict:
except Exception as err:
_LOGGER.exception("Unexpected error occurred")
raise UpdateFailed("An unexpected error occurred") from err
else:
# Process new orders that have not been seen before
new_orders = [
order for order in response.orders.order
if order.order_number not in self._last_orders
]
self._last_orders.update(order.order_number for order in new_orders)

# Calculate total values for the fetched orders
total_commissions = sum(float(order.estimated_paid_commission) for order in new_orders)
total_paid = sum(float(order.paid_amount) for order in new_orders)
total_orders = len(new_orders)

return {
"total_orders": total_orders,
"total_paid": total_paid,
"total_commissions": total_commissions
}
# Process new orders that have not been seen before
new_orders = [
order for order in response.orders.order
if order.order_number not in self._last_orders
]
self._last_orders.update(order.order_number for order in new_orders)

# Calculate total values for the fetched orders
total_commissions = sum(float(order.estimated_paid_commission) for order in new_orders)
total_paid = sum(float(order.paid_amount) for order in new_orders)
total_orders = len(new_orders)

return {
"total_orders": total_orders,
"total_paid": total_paid,
"total_commissions": total_commissions
}


class AliexpressCommissionsSensor(SensorEntity, CoordinatorEntity):
Expand Down

0 comments on commit 44f6fc3

Please sign in to comment.