Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/components/tankerkoenig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONF_LONGITUDE,
CONF_RADIUS,
CONF_SCAN_INTERVAL,
CONF_SHOW_ON_MAP,
)
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -52,6 +53,7 @@
vol.Optional(CONF_STATIONS, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(CONF_SHOW_ON_MAP, default=True): cv.boolean,
}
)
},
Expand Down Expand Up @@ -106,6 +108,7 @@ def __init__(self, hass, conf):
self.stations = {}
self.fuel_types = conf[CONF_FUEL_TYPES]
self.update_interval = conf[CONF_SCAN_INTERVAL]
self.show_on_map = conf[CONF_SHOW_ON_MAP]
Comment thread
bdraco marked this conversation as resolved.
self._hass = hass

def setup(self, latitude, longitude, radius, additional_stations):
Expand Down
21 changes: 17 additions & 4 deletions homeassistant/components/tankerkoenig/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ async def async_update_data():
)
continue
sensor = FuelPriceSensor(
fuel, station, coordinator, f"{NAME}_{station['name']}_{fuel}"
fuel,
station,
coordinator,
f"{NAME}_{station['name']}_{fuel}",
tankerkoenig.show_on_map,
)
entities.append(sensor)
_LOGGER.debug("Added sensors %s", entities)
Expand All @@ -70,7 +74,7 @@ async def async_update_data():
class FuelPriceSensor(Entity):
"""Contains prices for fuel in a given station."""

def __init__(self, fuel_type, station, coordinator, name):
def __init__(self, fuel_type, station, coordinator, name, show_on_map):
"""Initialize the sensor."""
self._station = station
self._station_id = station["id"]
Expand All @@ -84,6 +88,7 @@ def __init__(self, fuel_type, station, coordinator, name):
self._postcode = station["postCode"]
self._street = station["street"]
self._price = station[fuel_type]
self._show_on_map = show_on_map

@property
def name(self):
Expand Down Expand Up @@ -111,6 +116,11 @@ def state(self):
# key Fuel_type is not available when the fuel station is closed, use "get" instead of "[]" to avoid exceptions
return self._coordinator.data[self._station_id].get(self._fuel_type)

@property
def unique_id(self) -> str:
Comment thread
bdraco marked this conversation as resolved.
"""Return a unique identifier for this entity."""
return f"{self._station_id}_{self._fuel_type}"

@property
def device_state_attributes(self):
"""Return the attributes of the device."""
Expand All @@ -125,9 +135,12 @@ def device_state_attributes(self):
ATTR_HOUSE_NUMBER: self._house_number,
ATTR_POSTCODE: self._postcode,
ATTR_CITY: self._city,
ATTR_LATITUDE: self._latitude,
ATTR_LONGITUDE: self._longitude,
}

if self._show_on_map:
attrs[ATTR_LATITUDE] = self._latitude
attrs[ATTR_LONGITUDE] = self._longitude
Comment thread
bdraco marked this conversation as resolved.

if data is not None and "status" in data:
attrs[ATTR_IS_OPEN] = data["status"] == "open"
return attrs
Expand Down