Skip to content

Commit

Permalink
bump pyfuelprices
Browse files Browse the repository at this point in the history
ensure correct device_class is set
  • Loading branch information
pantherale0 authored Nov 23, 2024
1 parent bb7c5ba commit 98be68c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/fuel_prices/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"xmltodict",
"brotli",
"these-united-states==1.1.0.21",
"pyfuelprices==2024.11.4"
"pyfuelprices==2024.11.5"
],
"ssdp": [],
"version": "0.0.0",
Expand Down
13 changes: 11 additions & 2 deletions custom_components/fuel_prices/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import datetime, timedelta

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor.const import SensorDeviceClass
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS, CONF_NAME, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -117,6 +118,13 @@ def state_class(self) -> str:
return None
return "total"

@property
def device_class(self) -> SensorDeviceClass | None:
"""Return device class."""
if isinstance(self.native_value, str):
return None
return SensorDeviceClass.MONETARY


class CheapestFuelSensor(CheapestFuelEntity, SensorEntity):
"""A entity that shows the cheapest fuel for an area."""
Expand All @@ -126,6 +134,7 @@ class CheapestFuelSensor(CheapestFuelEntity, SensorEntity):
_last_update = None
_next_update = datetime.now()
_cached_data = None
_attr_device_class = SensorDeviceClass.MONETARY

async def async_update(self) -> None:
"""Update device data."""
Expand Down Expand Up @@ -176,6 +185,6 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return extra state attributes."""
data = self._cached_data
data["area"] = self._area
data["last_updated"] = self._last_update
data["next_update"] = self._next_update
data["sensor_last_poll"] = self._last_update
data["sensor_next_poll"] = self._next_update
return data
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ colorlog==6.7.0
homeassistant==2024.11.0
pip>=21.0,<23.2
ruff==0.0.292
pyfuelprices==2024.11.4
pyfuelprices==2024.11.5

0 comments on commit 98be68c

Please sign in to comment.