Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Arthur committed Apr 17, 2023
1 parent 1a3a519 commit b3e77f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/electric_kiwi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"iot_class": "cloud_polling",
"requirements": ["electrickiwi-api==0.8.0"],
"ssdp": [],
"version": "0.8",
"version": "0.8.5",
"zeroconf": []
}
22 changes: 17 additions & 5 deletions custom_components/electric_kiwi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timedelta
import logging

from electrickiwi_api.model import AccountBalance
from electrickiwi_api import ElectricKiwiApi
from electrickiwi_api.model import AccountBalance

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand All @@ -23,8 +23,8 @@
from homeassistant.util import dt as dt_util

from .const import (
ATTR_EK_HOP_START,
ATTR_EK_HOP_END,
ATTR_EK_HOP_START,
ATTR_HOP_PERCENTAGE,
ATTR_NEXT_BILLING_DATE,
ATTR_TOTAL_CURRENT_BALANCE,
Expand Down Expand Up @@ -106,7 +106,8 @@ class ElectricKiwiSensorEntityDescription(
name="Hour of free power end",
device_class=SensorDeviceClass.TIMESTAMP,
value_func=lambda hop: datetime.combine(
datetime.today(), datetime.strptime(hop.end.end_time, "%I:%M %p").time()
datetime.today(),
datetime.strptime(hop.end.end_time, "%I:%M %p").time(),
).astimezone(dt_util.DEFAULT_TIME_ZONE),
),
)
Expand Down Expand Up @@ -245,10 +246,21 @@ def name(self) -> str:
@property
def native_value(self) -> datetime | str | None:
"""Return the state of the sensor."""
return self.entity_description.value_func(
value = self.entity_description.value_func(
self._hop_coordinator.get_selected_hop()
)

end_time = datetime.combine(
datetime.today(),
datetime.strptime(
self._hop_coordinator.get_selected_hop().end.end_time, "%I:%M %p"
).time(),
).astimezone(dt_util.DEFAULT_TIME_ZONE)

if end_time < datetime.now().astimezone(dt_util.DEFAULT_TIME_ZONE):
return value + timedelta(days=1)
return value

@property
def extra_state_attributes(self) -> dict[str, str]:
"""Return the state attributes."""
Expand Down
3 changes: 2 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Displays financial information from your Electric Kiwi account

Sign in and enjoy

## TODO:

## Features
allow editing and automation of your hour of power
provides start and end date times for HOP intervals

0 comments on commit b3e77f7

Please sign in to comment.