Skip to content

Commit

Permalink
feat: integrating all sensors under a device
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorzin committed Dec 16, 2024
1 parent 6eb508c commit 983724c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions custom_components/aliexpress_openplatform/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import CURRENCY_EURO
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
Expand All @@ -30,6 +29,7 @@
from homeassistant.helpers.typing import StateType

_LOGGER = logging.getLogger(__name__)
CURRENCY_USD = "$"


async def async_setup_entry(
Expand Down Expand Up @@ -166,17 +166,27 @@ class AliexpressCommissionsSensor(SensorEntity, CoordinatorEntity):
"""Sensor for tracking total commissions earned."""

def __init__(self, coordinator: AliexpressOpenPlatformCoordinator) -> None:
"""Initialize the Total commissions' sensor."""
"""Initialize the Total commissions sensor."""
super().__init__(coordinator)
self._attr_unique_id = "aliexpress_total_commissions"
self.entity_description = SensorEntityDescription(
name="Total Commissions",
key="aliexpress_total_commissions",
icon="mdi:cash-multiple",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=CURRENCY_EURO,
native_unit_of_measurement=CURRENCY_USD,
)

@property
def device_info(self) -> dict[str, Any]:
"""Return device information for this sensor."""
return {
"identifiers": {(DOMAIN, "aliexpress_device")},
"name": "Aliexpress OpenPlatform",
"manufacturer": "Aliexpress",
"model": "OpenPlatform API",
}

@property
def native_value(self) -> StateType | date | datetime | Decimal:
"""Return the total commissions if data is available."""
Expand Down Expand Up @@ -210,6 +220,16 @@ def __init__(self, coordinator: AliexpressOpenPlatformCoordinator) -> None:
state_class=SensorStateClass.TOTAL_INCREASING,
)

@property
def device_info(self) -> dict[str, Any]:
"""Return device information for this sensor."""
return {
"identifiers": {(DOMAIN, "aliexpress_device")},
"name": "Aliexpress OpenPlatform",
"manufacturer": "Aliexpress",
"model": "OpenPlatform API",
}

@property
def native_value(self) -> StateType | date | datetime | Decimal:
"""Return the total number of orders if data is available."""
Expand Down Expand Up @@ -239,9 +259,19 @@ def __init__(self, coordinator: AliexpressOpenPlatformCoordinator) -> None:
key="aliexpress_total_paid",
icon="mdi:currency-usd",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=CURRENCY_EURO,
native_unit_of_measurement=CURRENCY_USD,
)

@property
def device_info(self) -> dict[str, Any]:
"""Return device information for this sensor."""
return {
"identifiers": {(DOMAIN, "aliexpress_device")},
"name": "Aliexpress OpenPlatform",
"manufacturer": "Aliexpress",
"model": "OpenPlatform API",
}

@property
def native_value(self) -> StateType | date | datetime | Decimal:
"""Return the total amount paid by customers if data is available."""
Expand Down

0 comments on commit 983724c

Please sign in to comment.