From ff7c117ea2c7909a373f8207a9c91472e1ca6b7a Mon Sep 17 00:00:00 2001 From: Alexander Ryazanov Date: Sat, 18 Sep 2021 05:25:39 +0300 Subject: [PATCH] feat: added entity grouping by `device_info` (fr #13) chore: bump underlying library version number (v0.0.21 -> v0.0.22) --- custom_components/lkcomu_interrao/_base.py | 28 +++++++++++++++++-- .../lkcomu_interrao/manifest.json | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/custom_components/lkcomu_interrao/_base.py b/custom_components/lkcomu_interrao/_base.py index a5b2534..c73273d 100644 --- a/custom_components/lkcomu_interrao/_base.py +++ b/custom_components/lkcomu_interrao/_base.py @@ -68,6 +68,7 @@ DATA_FINAL_CONFIG, DATA_PROVIDER_LOGOS, DATA_UPDATE_DELEGATORS, + DOMAIN, FORMAT_VAR_ACCOUNT_CODE, FORMAT_VAR_ACCOUNT_ID, FORMAT_VAR_CODE, @@ -373,6 +374,28 @@ def __init__( self._account_config: ConfigType = account_config self._entity_updater = None + @property + def api_hostname(self) -> str: + return urlparse(self._account.api.BASE_URL).netloc + + @property + def device_info(self) -> Dict[str, Any]: + account_object = self._account + + device_info = { + "name": f"№ {account_object.code}", + "identifiers": {(DOMAIN, f"{account_object.__class__.__name__}__{account_object.id}")}, + "manufacturer": account_object.provider_name, + "model": self.api_hostname, + "sw_version": account_object.api.APP_VERSION, # placeholder for future releases + } + + account_address = account_object.address + if account_address is not None: + device_info["suggested_area"] = account_address + + return device_info + def _handle_dev_presentation( self, mapping: MutableMapping[str, Any], @@ -442,8 +465,9 @@ def device_state_attributes(self): """Return the attribute(s) of the sensor""" attributes = { - ATTR_ATTRIBUTION: (ATTRIBUTION_RU if IS_IN_RUSSIA else ATTRIBUTION_EN) - % urlparse(self._account.api.BASE_URL).netloc, + ATTR_ATTRIBUTION: ( + (ATTRIBUTION_RU if IS_IN_RUSSIA else ATTRIBUTION_EN) % self.api_hostname + ), **(self.sensor_related_attributes or {}), } diff --git a/custom_components/lkcomu_interrao/manifest.json b/custom_components/lkcomu_interrao/manifest.json index 0d7d95d..63606ed 100644 --- a/custom_components/lkcomu_interrao/manifest.json +++ b/custom_components/lkcomu_interrao/manifest.json @@ -10,7 +10,7 @@ "python-dateutil==2.8.1", "cached-property==1.5.1", "fake_useragent==0.1.11", - "inter-rao-energosbyt-python==0.0.21" + "inter-rao-energosbyt-python==0.0.22" ], "config_flow": true, "iot_class": "cloud_polling"