Skip to content

Commit

Permalink
feat: added entity grouping by device_info (fr #13)
Browse files Browse the repository at this point in the history
chore: bump underlying library version number (v0.0.21 -> v0.0.22)
  • Loading branch information
alryaz committed Sep 18, 2021
1 parent a5d6dda commit ff7c117
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions custom_components/lkcomu_interrao/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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 {}),
}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/lkcomu_interrao/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ff7c117

Please sign in to comment.