Skip to content

Commit

Permalink
Attributo per arrotondamenti
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualdj committed Dec 10, 2022
1 parent beeb66e commit d239dae
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion custom_components/pun_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from typing import Any, Dict

from . import PUNDataUpdateCoordinator
from .const import (
Expand All @@ -17,6 +18,7 @@
PUN_FASCIA_F2,
PUN_FASCIA_F3,
)
ATTR_ROUNDED_DECIMALS = "rounded_decimals"

import logging
_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -111,6 +113,14 @@ def name(self) -> str:
else:
return None

@property
def extra_state_attributes(self) -> Dict[str, Any]:
"""Restituisce gli attributi di stato"""
state_attr = {
ATTR_ROUNDED_DECIMALS: round(self.native_value, 3)
}
return state_attr

class FasciaPUNSensorEntity(CoordinatorEntity, SensorEntity):
"""Sensore che rappresenta la fascia PUN corrente"""

Expand Down Expand Up @@ -205,4 +215,12 @@ def entity_id(self) -> str:
@property
def name(self) -> str:
"""Restituisce il nome del sensore"""
return "Prezzo fascia corrente"
return "Prezzo fascia corrente"

@property
def extra_state_attributes(self) -> Dict[str, Any]:
"""Restituisce gli attributi di stato"""
state_attr = {
ATTR_ROUNDED_DECIMALS: round(self.native_value, 3)
}
return state_attr

0 comments on commit d239dae

Please sign in to comment.