diff --git a/custom_components/nova_poshta/manifest.json b/custom_components/nova_poshta/manifest.json index 9742e6b..ba656aa 100644 --- a/custom_components/nova_poshta/manifest.json +++ b/custom_components/nova_poshta/manifest.json @@ -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" } diff --git a/custom_components/nova_poshta/sensor.py b/custom_components/nova_poshta/sensor.py index 7809d95..90da92c 100644 --- a/custom_components/nova_poshta/sensor.py +++ b/custom_components/nova_poshta/sensor.py @@ -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, @@ -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)}, @@ -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"])