11"""Platform for sensor integration."""
22from __future__ import annotations
33
4- import aiohttp
54import logging
6-
5+ import unicodedata
76from datetime import timedelta
87from typing import Any , Dict
98
9+ import aiohttp
1010from homeassistant .components .sensor import (SensorDeviceClass , SensorEntity ,
1111 SensorStateClass )
1212from homeassistant .config_entries import ConfigEntry
1515from homeassistant .helpers .entity_platform import AddEntitiesCallback
1616
1717from .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 )
2323from .dgeg import DGEG , Station
2424
2727# Time between updating data from API
2828SCAN_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