Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sensor:
sensor:
- platform: apparent_temperature
name: 'Basement Feels Like Temperature'
precision: 2
source:
- sensor.basement_temperature
- sensor.basement_humidity
Expand Down Expand Up @@ -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].
Expand Down
14 changes: 12 additions & 2 deletions custom_components/apparent_temperature/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
}
)

Expand All @@ -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),
)
]
)
Expand All @@ -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
Expand Down
Loading