Skip to content

Commit

Permalink
Merge pull request #135 from c-st/precision
Browse files Browse the repository at this point in the history
Set suggested precision for sensors
  • Loading branch information
c-st authored Jul 30, 2024
2 parents d8cdd52 + 85ec036 commit 6eefb11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

target-version = "py310"

[lint]
select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
Expand All @@ -25,7 +26,6 @@ select = [
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
Expand All @@ -39,9 +39,5 @@ ignore = [
"UP006",
"UP007",
]

[flake8-pytest-style]
fixture-parentheses = false

[mccabe]
max-complexity = 25
mccabe.max-complexity = 25
flake8-pytest-style.fixture-parentheses = false
5 changes: 5 additions & 0 deletions custom_components/auto_areas/auto_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def device_info(self) -> DeviceInfo:
"suggested_area": self.auto_area.area_name,
}

@cached_property
def suggested_display_precision(self) -> int | None:
"""Set the suggested precision (0.12)."""
return 2

async def async_added_to_hass(self):
"""Start tracking sensors."""
LOGGER.debug(
Expand Down
6 changes: 6 additions & 0 deletions custom_components/auto_areas/sensors/illuminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def native_unit_of_measurement(self) -> str | None:
"""Return unit of measurement."""
return LIGHT_LUX

@override
@cached_property
def suggested_display_precision(self) -> int | None:
"""Set the suggested precision (0)."""
return 0

@property
def state(self) -> Any: # type: ignore
"""Return the state of the entity."""
Expand Down

0 comments on commit 6eefb11

Please sign in to comment.