From 983724cc21b80f1d64926b7873d3dc21749fb6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Mart=C3=ADnez?= <103188721+hectorzin@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:43:07 +0100 Subject: [PATCH] feat: integrating all sensors under a device --- .../aliexpress_openplatform/sensor.py | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/custom_components/aliexpress_openplatform/sensor.py b/custom_components/aliexpress_openplatform/sensor.py index 22c0939..b41bd97 100644 --- a/custom_components/aliexpress_openplatform/sensor.py +++ b/custom_components/aliexpress_openplatform/sensor.py @@ -11,7 +11,6 @@ SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import CURRENCY_EURO from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -30,6 +29,7 @@ from homeassistant.helpers.typing import StateType _LOGGER = logging.getLogger(__name__) +CURRENCY_USD = "$" async def async_setup_entry( @@ -166,7 +166,7 @@ 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( @@ -174,9 +174,19 @@ def __init__(self, coordinator: AliexpressOpenPlatformCoordinator) -> None: 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.""" @@ -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.""" @@ -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."""