diff --git a/custom_components/uster_waste/__init__.py b/custom_components/uster_waste/__init__.py index 7506e2d..84a10ae 100644 --- a/custom_components/uster_waste/__init__.py +++ b/custom_components/uster_waste/__init__.py @@ -1,45 +1,21 @@ """Uster Waste integration.""" from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.const import Platform, SERVICE_UPDATE_ENTITY +from homeassistant.const import Platform from .const import DOMAIN -PLATFORMS = [Platform.SENSOR] +PLATFORMS = [Platform.SENSOR, Platform.BUTTON] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Uster Waste from a config entry.""" hass.data.setdefault(DOMAIN, {})[entry.entry_id] = entry.data - # Register manual refresh service - hass.services.async_register( - DOMAIN, - entry.data.get("name", "uster_waste"), - async_handle_manual_refresh - ) - await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - if unload_ok: - hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok - - -async def async_handle_manual_refresh(service): - """Handle manual refresh service call.""" - entry_id = service.data.get("entry_id") - if not entry_id or entry_id not in hass.data[DOMAIN]: - return - - # Trigger update for all sensors under this entry - await hass.services.async_call( - "homeassistant", "update_entity", - {"entity_id": [f"sensor.uster_waste_{entry_id}"]}, - blocking=False, - ) + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/custom_components/uster_waste/__pycache__/__init__.cpython-313.pyc b/custom_components/uster_waste/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..efc90eb Binary files /dev/null and b/custom_components/uster_waste/__pycache__/__init__.cpython-313.pyc differ diff --git a/custom_components/uster_waste/__pycache__/button.cpython-313.pyc b/custom_components/uster_waste/__pycache__/button.cpython-313.pyc new file mode 100644 index 0000000..c1be01d Binary files /dev/null and b/custom_components/uster_waste/__pycache__/button.cpython-313.pyc differ diff --git a/custom_components/uster_waste/__pycache__/config_flow.cpython-313.pyc b/custom_components/uster_waste/__pycache__/config_flow.cpython-313.pyc new file mode 100644 index 0000000..ad2d10a Binary files /dev/null and b/custom_components/uster_waste/__pycache__/config_flow.cpython-313.pyc differ diff --git a/custom_components/uster_waste/__pycache__/const.cpython-313.pyc b/custom_components/uster_waste/__pycache__/const.cpython-313.pyc new file mode 100644 index 0000000..b95b638 Binary files /dev/null and b/custom_components/uster_waste/__pycache__/const.cpython-313.pyc differ diff --git a/custom_components/uster_waste/__pycache__/sensor.cpython-313.pyc b/custom_components/uster_waste/__pycache__/sensor.cpython-313.pyc new file mode 100644 index 0000000..3702d83 Binary files /dev/null and b/custom_components/uster_waste/__pycache__/sensor.cpython-313.pyc differ diff --git a/custom_components/uster_waste/button.py b/custom_components/uster_waste/button.py index ed387ed..2b804a5 100644 --- a/custom_components/uster_waste/button.py +++ b/custom_components/uster_waste/button.py @@ -1,6 +1,5 @@ """Button platform for Uster Waste.""" import logging -from typing import Optional from homeassistant.components.button import ButtonEntity from homeassistant.config_entries import ConfigEntry @@ -18,12 +17,9 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the button.""" - config = entry.data - name = config.get("name", "Uster Waste") - entity = UsterWasteButton( entry_id=entry.entry_id, - name=name + name=entry.data.get("name", "Uster Waste") ) async_add_entities([entity]) @@ -45,22 +41,16 @@ class UsterWasteButton(ButtonEntity): async def async_press(self) -> None: """Handle the button press (manual refresh).""" - # Trigger a manual update of the sensor - hass = self.hass - coordinator = None + # Trigger a manual update by calling the sensor's update method + # The sensor will fetch fresh data from the Uster website + entity_registry = self.hass.data["entity_registry"] - # Find the coordinator for this entry - if DOMAIN in hass.data: - for entry_id, entry_data in hass.data[DOMAIN].items(): - if entry_id == self._entry_id and "coordinator" in entry_data: - coordinator = entry_data["coordinator"] - break + # Find the sensor entity for this entry + entity_id = f"sensor.uster_waste_{self._entry_id}" - if coordinator: - await coordinator.async_update() - # Force sensor to update - for entity in coordinator.entities: - await entity.async_update() - entity.async_write_ha_state() - else: - _LOGGER.error("Coordinator not found for manual refresh") \ No newline at end of file + # Trigger update for the sensor + await self.hass.services.async_call( + "homeassistant", "update_entity", + {"entity_id": entity_id}, + blocking=False, + )