Skip to content

Commit

Permalink
Merge pull request #10 from fars-fede-fire/round_state
Browse files Browse the repository at this point in the history
Round state to 2 decimals
  • Loading branch information
fars-fede-fire authored May 21, 2023
2 parents 990ffa5 + 43b5bbe commit 429a38e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions custom_components/price_calc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
For more details about this integration, please refer to
https://github.com/fars-fede-fire/price_calc
"""

from __future__ import annotations

from asyncio import sleep
Expand Down
2 changes: 1 addition & 1 deletion custom_components/price_calc/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
)
)
self.listeners.append(
async_track_time_change(self.hass, self.time_update, second=[0, 20, 40])
async_track_time_change(self.hass, self.time_update, second=[0])
)

super().__init__(
Expand Down
4 changes: 3 additions & 1 deletion custom_components/price_calc/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"numpy",
"pydantic"
],
"dependencies": [],
"dependencies": [
"recorder"
],
"after-dependencies": [
"energidataservice"
],
Expand Down
13 changes: 6 additions & 7 deletions custom_components/price_calc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,25 @@ class PriceCalcEntityMixin:

@dataclass
class PriceCalcSensorEntityDescription(SensorEntityDescription, PriceCalcEntityMixin):
"""Price calc sensor description"""
"""Price calc sensor description."""

key: str
has_entity_name: bool = False
device_class = SensorDeviceClass.MONETARY
icon: str = "mdi:timer-play-outline"
native_unit_of_measurement = SensorDeviceClass.MONETARY
suggested_display_precision = 3


SENSORS = [
PriceCalcSensorEntityDescription(
key="price_now",
value_fn=lambda x: x.updated.current_price,
value_fn=lambda x: round(x.updated.current_price,2),
attrs={
"current time": lambda x: x.updated.current_time,
"next lowest": lambda x: x.updated.next_lowest_price_dt,
"next lowest price": lambda x: x.updated.next_low_price,
"current_time": lambda x: x.updated.current_time,
"next_lowest": lambda x: x.updated.next_lowest_price_dt,
"next_lowest price": lambda x: x.updated.next_low_price,
"diff_now_and_next_lowest": lambda x: x.updated.diff_now_and_next_lowest,
"delay hours": lambda x: x.updated.delay_hours,
"delay_hours": lambda x: x.updated.delay_hours,
"delay_hours_price": lambda x: x.updated.delay_hours_price,
"diff_now_and_delay": lambda x: x.updated.diff_now_and_delay,
"todays_highest": lambda x: x.calcs.highest_price,
Expand Down

0 comments on commit 429a38e

Please sign in to comment.