diff --git a/custom_components/fuel_prices/entity.py b/custom_components/fuel_prices/entity.py index 819cb95..d4c8f73 100644 --- a/custom_components/fuel_prices/entity.py +++ b/custom_components/fuel_prices/entity.py @@ -2,6 +2,7 @@ from __future__ import annotations +from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import CoordinatorEntity from .coordinator import FuelPricesCoordinator @@ -35,13 +36,12 @@ def unique_id(self) -> str | None: return f"fuelprices_{self._fuel_station_id}_{self._entity_id}" -class CheapestFuelEntity(CoordinatorEntity): +class CheapestFuelEntity(Entity): """Represents a fuel.""" def __init__( self, coordinator: FuelPricesCoordinator, count: str, area: str, fuel: str, coords: tuple, radius: float): """Initialize.""" - super().__init__(coordinator) self.coordinator: FuelPricesCoordinator = coordinator self._count = count self._area = area diff --git a/custom_components/fuel_prices/manifest.json b/custom_components/fuel_prices/manifest.json index 99d9c6a..b3d9897 100644 --- a/custom_components/fuel_prices/manifest.json +++ b/custom_components/fuel_prices/manifest.json @@ -13,7 +13,7 @@ "xmltodict", "brotli", "these-united-states==1.1.0.21", - "pyfuelprices==2024.11.2" + "pyfuelprices==2024.11.4" ], "ssdp": [], "version": "0.0.0", diff --git a/custom_components/fuel_prices/sensor.py b/custom_components/fuel_prices/sensor.py index 584bf71..6453495 100644 --- a/custom_components/fuel_prices/sensor.py +++ b/custom_components/fuel_prices/sensor.py @@ -20,6 +20,8 @@ _LOGGER = logging.getLogger(__name__) +SCAN_INTERVAL = timedelta(minutes=1) + async def async_setup_entry( hass: HomeAssistant, entry: FuelPricesConfigEntry, async_add_entities: AddEntitiesCallback @@ -119,6 +121,7 @@ def state_class(self) -> str: class CheapestFuelSensor(CheapestFuelEntity, SensorEntity): """A entity that shows the cheapest fuel for an area.""" + _attr_force_update = True _attr_should_poll = True # we need to query the module for this data _last_update = None _next_update = datetime.now() @@ -136,11 +139,11 @@ async def async_update(self) -> None: radius=self._radius ) if len(data) >= (int(self._count)-1): + self._last_update = datetime.now() + self._next_update = datetime.now() + timedelta(minutes=5) self._cached_data = data[int(self._count)-1] return True self._cached_data = None - self._last_update = datetime.now() - self._next_update = datetime.now() + timedelta(minutes=5) @property def native_value(self) -> str | float: @@ -154,6 +157,13 @@ def name(self) -> str: """Name of the entity.""" return f"{self._area} cheapest {self._fuel} {self._count}" + @property + def native_unit_of_measurement(self) -> str: + """Return unit of measurement.""" + if isinstance(self.native_value, float): + return self._cached_data["currency"] + return None + @property def state_class(self) -> str: """Return state type.""" @@ -164,9 +174,8 @@ def state_class(self) -> str: @property def extra_state_attributes(self) -> Mapping[str, Any] | None: """Return extra state attributes.""" - return { - "area": self._area, - **self._cached_data, - "last_updated": self._last_update, - "next_update": self._next_update - } + data = self._cached_data + data["area"] = self._area + data["last_updated"] = self._last_update + data["next_update"] = self._next_update + return data diff --git a/requirements.txt b/requirements.txt index 7f621a4..db5dbcb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ colorlog==6.7.0 -git+https://github.com/home-assistant/core@dev +# git+https://github.com/home-assistant/core@dev +homeassistant==2024.11.0 pip>=21.0,<23.2 ruff==0.0.292 -pyfuelprices==2024.11.2 \ No newline at end of file +pyfuelprices==2024.11.4 \ No newline at end of file