Skip to content

Commit

Permalink
Fix unique id and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
krasnoukhov committed Oct 21, 2023
1 parent cfe4747 commit 9bc3ace
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions custom_components/nova_poshta/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/krasnoukhov/homeassistant-nova-poshta/issues",
"requirements": ["transliterate==1.10.2", "git+https://github.com/krasnoukhov/novaposhta-python-client.git@errors#novaposhta-python-client==0.1.2"],
"version": "1.0.0-beta.1"
"requirements": ["transliterate==1.10.2", "stringcase>=1.2.0", "git+https://github.com/krasnoukhov/novaposhta-python-client.git@errors#novaposhta-python-client==0.1.2"],
"version": "1.0.0-beta.2"
}
21 changes: 14 additions & 7 deletions custom_components/nova_poshta/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def async_setup_entry(
class NovaPoshtaSensor(NovaPoshtaEntity, SensorEntity):
"""Representation of the Nova Poshta sensor."""

_parcels: list[dict]
_warehouse: dict

def __init__(
self,
Expand All @@ -56,15 +56,18 @@ def __init__(
"""Initialize a Nova Poshta entity."""
super().__init__(coordinator)

warehouse_info = dict(warehouse)
self._parcels = self.coordinator.delivered_by_warehouse(warehouse_info["id"])

self._warehouse = dict(warehouse)
self.entity_description = SensorEntityDescription(
key=f"delivered_parcels_{snakecase(warehouse_info['name'])}_{warehouse_info['id']}",
name=f"Delivered parcels in {warehouse_info['name']}@{warehouse_info['id']}",
key=f"delivered_parcels_{snakecase(self._warehouse['name'])}_{self._warehouse['id']}",
name=f"Delivered parcels in {self._warehouse['name']}@{self._warehouse['id']}",
state_class=SensorStateClass.TOTAL,
)
self._attr_unique_id = self.entity_description.key
self._attr_unique_id = "-".join(
[
entry.entry_id,
self.entity_description.key,
]
)
self._attr_device_info = DeviceInfo(
name=entry.title,
identifiers={(DOMAIN, entry.entry_id)},
Expand All @@ -87,3 +90,7 @@ def extra_state_attributes(self) -> dict[str, str] | None:
)
)
}

@property
def _parcels(self) -> list[dict]:
return self.coordinator.delivered_by_warehouse(self._warehouse["id"])

0 comments on commit 9bc3ace

Please sign in to comment.