diff --git a/README.md b/README.md index d9d92ca..51f10bf 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ sensor: sensor: - platform: apparent_temperature name: 'Basement Feels Like Temperature' + precision: 2 source: - sensor.basement_temperature - sensor.basement_humidity @@ -95,6 +96,10 @@ I put a lot of work into making this repo and component available and updated to > **_Note_**: > You can use site [uuidgenerator.net](https://www.uuidgenerator.net/) to generate unique ID's. +**precision**\ + _(integer) (Optional) (Default value: 1)_\ + Number of decimal places to display (0-6). + ## Track updates You can automatically track new versions of this component and update it by [HACS][hacs]. diff --git a/custom_components/apparent_temperature/sensor.py b/custom_components/apparent_temperature/sensor.py index b4a9fbf..2506f4b 100644 --- a/custom_components/apparent_temperature/sensor.py +++ b/custom_components/apparent_temperature/sensor.py @@ -67,11 +67,16 @@ _LOGGER = logging.getLogger(__name__) +CONF_PRECISION = "precision" + PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend( { vol.Required(CONF_SOURCE): cv.entity_ids, vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_UNIQUE_ID): cv.string, + vol.Optional(CONF_PRECISION, default=1): vol.All( + vol.Coerce(int), vol.Range(min=0, max=6) + ), } ) @@ -93,6 +98,7 @@ async def async_setup_platform( config.get(CONF_UNIQUE_ID), config.get(CONF_NAME), expand_entity_ids(hass, config.get(CONF_SOURCE)), + config.get(CONF_PRECISION), ) ] ) @@ -107,14 +113,18 @@ class ApparentTemperatureSensor(SensorEntity): _attr_state_class = SensorStateClass.MEASUREMENT _attr_should_poll = False _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS - _attr_suggested_display_precision = 1 def __init__( - self, unique_id: str | None, name: str | None, sources: list[str] + self, + unique_id: str | None, + name: str | None, + sources: list[str], + precision: int = 1, ) -> None: """Class initialization.""" self._attr_unique_id = unique_id self._attr_native_value = None + self._attr_suggested_display_precision = precision self._name = name self._sources = sources