diff --git a/homeassistant/components/tankerkoenig/__init__.py b/homeassistant/components/tankerkoenig/__init__.py index e8b4e92327c..bf2468b704c 100755 --- a/homeassistant/components/tankerkoenig/__init__.py +++ b/homeassistant/components/tankerkoenig/__init__.py @@ -13,6 +13,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_RADIUS, CONF_SCAN_INTERVAL, + CONF_SHOW_ON_MAP, ) from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv @@ -52,6 +53,7 @@ CONFIG_SCHEMA = vol.Schema( vol.Optional(CONF_STATIONS, default=[]): vol.All( cv.ensure_list, [cv.string] ), + vol.Optional(CONF_SHOW_ON_MAP, default=True): cv.boolean, } ) }, @@ -106,6 +108,7 @@ class TankerkoenigData: 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] self._hass = hass def setup(self, latitude, longitude, radius, additional_stations): diff --git a/homeassistant/components/tankerkoenig/sensor.py b/homeassistant/components/tankerkoenig/sensor.py index 2fb184848ea..d78b5eb2641 100755 --- a/homeassistant/components/tankerkoenig/sensor.py +++ b/homeassistant/components/tankerkoenig/sensor.py @@ -59,7 +59,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) 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) @@ -70,7 +74,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= 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"] @@ -84,6 +88,7 @@ class FuelPriceSensor(Entity): self._postcode = station["postCode"] self._street = station["street"] self._price = station[fuel_type] + self._show_on_map = show_on_map @property def name(self): @@ -111,6 +116,11 @@ class FuelPriceSensor(Entity): # 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: + """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.""" @@ -125,9 +135,12 @@ class FuelPriceSensor(Entity): 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 + if data is not None and "status" in data: attrs[ATTR_IS_OPEN] = data["status"] == "open" return attrs