Skip to content

Commit e46d5a9

Browse files
p1nh3iroPinheiro
andauthored
improve entity_picture (#20)
Co-authored-by: Pinheiro <jose.alberto@ebankit.com>
1 parent d45142f commit e46d5a9

File tree

1 file changed

+17
-16
lines changed
  • custom_components/precoscombustiveis

1 file changed

+17
-16
lines changed

custom_components/precoscombustiveis/sensor.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Platform for sensor integration."""
22
from __future__ import annotations
33

4-
import aiohttp
54
import logging
6-
5+
import unicodedata
76
from datetime import timedelta
87
from typing import Any, Dict
98

9+
import aiohttp
1010
from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity,
1111
SensorStateClass)
1212
from homeassistant.config_entries import ConfigEntry
@@ -15,10 +15,10 @@
1515
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1616

1717
from .const import (
18-
DEFAULT_ICON,
19-
DOMAIN,
20-
UNIT_OF_MEASUREMENT,
21-
ATTRIBUTION,
18+
DEFAULT_ICON,
19+
DOMAIN,
20+
UNIT_OF_MEASUREMENT,
21+
ATTRIBUTION,
2222
CONF_STATIONID)
2323
from .dgeg import DGEG, Station
2424

@@ -27,20 +27,20 @@
2727
# Time between updating data from API
2828
SCAN_INTERVAL = timedelta(minutes=60)
2929

30-
async def async_setup_entry(hass: HomeAssistant,
31-
config_entry: ConfigEntry,
30+
async def async_setup_entry(hass: HomeAssistant,
31+
config_entry: ConfigEntry,
3232
async_add_entities: AddEntitiesCallback):
3333
"""Setup sensor platform."""
3434
session = async_get_clientsession(hass, True)
3535
api = DGEG(session)
3636

3737
config = config_entry.data
3838
station = await api.getStation(config[CONF_STATIONID])
39-
39+
4040
sensors = [PrecosCombustiveisSensor(
41-
api,
42-
config[CONF_STATIONID],
43-
station,
41+
api,
42+
config[CONF_STATIONID],
43+
station,
4444
fuel["TipoCombustivel"]
4545
) for fuel in station.fuels]
4646
async_add_entities(sensors, update_before_add=True)
@@ -55,7 +55,7 @@ def __init__(self, api: DGEG, stationId: float, station: Station, fuelName: str)
5555
self._stationId = stationId
5656
self._station = station
5757
self._fuelName = fuelName
58-
58+
5959
self._icon = DEFAULT_ICON
6060
self._unit_of_measurement = UNIT_OF_MEASUREMENT
6161
self._device_class = SensorDeviceClass.MONETARY
@@ -101,9 +101,10 @@ def icon(self):
101101

102102
@property
103103
def entity_picture(self):
104-
"""Return the entity picture."""
104+
"""Return the entity picture."""
105105
if self._station.brand and self._station.brand.lower() != "genérico":
106-
brand_name = self._station.brand.lower().replace(" ", "_").replace("-", "_")
106+
brand_name = unicodedata.normalize('NFD', self._station.brand.lower())
107+
brand_name = ''.join(c for c in brand_name if c.isalpha())
107108
return f"/local/precoscombustiveis/{brand_name}.png"
108109
else:
109110
return ""
@@ -124,7 +125,7 @@ def extra_state_attributes(self) -> Dict[str, Any]:
124125
"Longitude": self._station.longitude,
125126
"StationType": self._station.type,
126127
"LastPriceUpdate": self._station.getLastUpdate(self._fuelName),
127-
}
128+
}
128129

129130
async def async_update(self) -> None:
130131
"""Fetch new state data for the sensor."""

0 commit comments

Comments
 (0)