Skip to content

Commit

Permalink
3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed May 11, 2024
1 parent a09d7ca commit 1a26227
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions custom_components/peaqev/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/elden1337/hass-peaq/issues",
"requirements": [
"peaqevcore==19.9.4"
"peaqevcore==19.10.3"
],
"version": "3.5.0"
"version": "3.6.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ def defer_start(non_hours: list) -> bool:
"""Defer starting if next hour is a non-hour and minute is 50 or greater, to avoid short running times."""
if (datetime.now() + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0) in non_hours:
if datetime.now().minute >= 50:
#_LOGGER.debug("Deferring start due to upcoming non-hour")
return True
return False
3 changes: 3 additions & 0 deletions custom_components/peaqev/peaqservice/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def _request_sensor_lookup(self) -> dict:
IS_SCHEDULER_ACTIVE: partial(
getattr, self.hours.scheduler, 'scheduler_active', False
),
'schedules': partial(
getattr, self.hours.scheduler, 'schedules', {}
),
CHARGECONTROLLER_STATUS: partial(
getattr, self.chargecontroller, 'status_string'
),
Expand Down
12 changes: 6 additions & 6 deletions custom_components/peaqev/peaqservice/hub/servicecalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ async def async_call_schedule_needed_charge(
dep_time = None
start_time = None
try:
dep_time = datetime.strptime(departure_time, "%Y-%m-%d %H:%M")
dep_time = datetime.strptime(departure_time, '%Y-%m-%d %H:%M')
except ValueError:
_LOGGER.error(f"Could not parse departure time: {departure_time}")
_LOGGER.error(f'Could not parse departure time: {departure_time}')
if schedule_starttime is not None:
try:
start_time = datetime.strptime(schedule_starttime, "%Y-%m-%d %H:%M")
start_time = datetime.strptime(schedule_starttime, '%Y-%m-%d %H:%M')
except ValueError:
_LOGGER.error(f"Could not parse schedule start time: {schedule_starttime}")
_LOGGER.error(f'Could not parse schedule start time: {schedule_starttime}')
else:
start_time = datetime.now()
_LOGGER.debug(
f"scheduler params. charge: {charge_amount}, dep-time: {dep_time}, start_time: {start_time}"
f'scheduler params. charge: {charge_amount}, dep-time: {dep_time}, start_time: {start_time}'
)
await self.hub.hours.scheduler.async_create_schedule(
charge_amount, dep_time, start_time, override_settings
Expand All @@ -65,5 +65,5 @@ async def async_call_schedule_needed_charge(

async def async_call_scheduler_cancel(self):
if self.hub.hours.price_aware:
await self.hub.hours.hub.scheduler.async_cancel_facade()
await self.hub.hours.scheduler.async_cancel_facade()
await self.hub.observer.async_broadcast(ObserverTypes.SchedulerCancelled)
4 changes: 4 additions & 0 deletions custom_components/peaqev/sensors/chargercontroller_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, hub: HomeAssistantHub, entry_id):
self._current_hour = None
self._price_aware: bool = False
self._scheduler_active: bool = False
self._schedules = None

@property
def state(self):
Expand Down Expand Up @@ -57,6 +58,7 @@ async def async_update(self) -> None:
'hour_state',
'is_price_aware',
'is_scheduler_active',
'schedules'
)
if ret is not None:
self._state = ret.get('chargecontroller_status')
Expand All @@ -65,6 +67,7 @@ async def async_update(self) -> None:
self._current_hour = ret.get('hour_state')
self._price_aware = ret.get('is_price_aware')
self._scheduler_active = ret.get('is_scheduler_active')
self._schedules = ret.get('schedules')

@property
def extra_state_attributes(self) -> dict:
Expand All @@ -77,4 +80,5 @@ def extra_state_attributes(self) -> dict:
attr_dict['non_hours'] = self.hub.options.nonhours
attr_dict['current_hour state'] = self._current_hour
attr_dict['scheduler_active'] = self._scheduler_active
attr_dict['schedules'] = self._schedules
return attr_dict
40 changes: 21 additions & 19 deletions custom_components/peaqev/sensors/money_sensor_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def calculate_stop_len(nonhours) -> str:
ret = ""
ret = ''
for idx, h in enumerate(nonhours):
if idx + 1 < len(nonhours):
if _get_uneven(nonhours[idx + 1], nonhours[idx]):
Expand All @@ -28,8 +28,8 @@ def _get_stopped_string(
) -> str: # todo: find out if stopped til further notice instead and type that.
val = h + 1 if h + 1 < 24 else h + 1 - 24
if val < 10:
return f"Charging stopped until 0{val}:00"
return f"Charging stopped until {val}:00"
return f'Charging stopped until 0{val}:00'
return f'Charging stopped until {val}:00'


def _get_uneven(first, second) -> bool:
Expand All @@ -49,38 +49,40 @@ def set_avg_cost(avg_cost, currency, use_cent) -> str:
override = currency_translation(
value=avg_cost[1], currency=currency, use_cent=use_cent
)
return f"{override} ({standard})"
return f"{standard}"
return f'{override} ({standard})'
return f'{standard}'


def set_total_charge(max_charge) -> str:
if max_charge[1] is not None:
if max_charge[1] != max_charge[0]:
return f"{max_charge[1]} kWh ({max_charge[0]} kWh)"
return f"{max_charge[0]} kWh"
return f'{max_charge[1]} kWh ({max_charge[0]} kWh)'
return f'{max_charge[0]} kWh'


def set_all_hours_display(future_hours: list[HourPrice], tomorrow_valid: bool) -> dict[str, str]:
ret = {}
for h in future_hours:
dt_string = f"{h.dt.hour:02d}:{h.dt.minute:02d}"
dt_string = f'{h.dt.hour:02d}:{h.dt.minute:02d}'
if h.dt.date() == datetime.now().date():
dt_string = f"{dt_string}"
dt_string = f'{dt_string}'
elif h.dt.date() == datetime.now().date()+timedelta(days=1) and tomorrow_valid:
dt_string = f"{dt_string}⁺¹"
dt_string = f'{dt_string}⁺¹'
else:
_LOGGER.warning(f"Invalid hour {h.dt} in all_hours_display. Tomorrow valid {tomorrow_valid} and hourdate is {h.dt.date()}")
_LOGGER.warning(f'Invalid hour {h.dt} in all_hours_display. Tomorrow valid {tomorrow_valid} and hourdate is {h.dt.date()}')

match h.permittance:
case 0:
ret[str(dt_string)] = "—"
ret[str(dt_string)] = '—'
case 1:
ret[str(dt_string)] = "Charge"
ret[str(dt_string)] = 'Charge'
case _:
ret[str(dt_string)] = f"Caution {str(int(h.permittance * 100))}%"
ret[str(dt_string)] = f'Caution {str(int(h.permittance * 100))}%'

if h.permittance_type is PermittanceType.MaxMin:
ret[str(dt_string)] = f"{ret[str(dt_string)]} ★"
ret[str(dt_string)] = f'{ret[str(dt_string)]} ★'
if h.permittance_type is PermittanceType.Scheduler:
ret[str(dt_string)] = f'{ret[str(dt_string)]} ⏲'

return ret

Expand All @@ -90,7 +92,7 @@ def set_non_hours_display(non_hours: list[datetime]) -> list:
now = datetime.now().replace(minute=0, second=0, microsecond=0)
for i in non_hours:
if i.date() > now.date():
ret.append(f"{str(i.hour)}⁺¹")
ret.append(f'{str(i.hour)}⁺¹')
elif i.date() == now.date():
ret.append(str(i.hour))
return ret
Expand All @@ -101,10 +103,10 @@ def set_caution_hours_display(dynamic_caution_hours: dict[datetime, float]) -> d
if len(dynamic_caution_hours) > 0:
for h in dynamic_caution_hours:
if h.date() > datetime.now().date():
hh = f"{h.hour}⁺¹"
hh = f'{h.hour}⁺¹'
else:
hh = h.hour
ret[hh] = f"{str((int(dynamic_caution_hours.get(h, 0) * 100)))}%"
ret[hh] = f'{str((int(dynamic_caution_hours.get(h, 0) * 100)))}%'
return ret


Expand All @@ -115,4 +117,4 @@ def set_current_charge_permittance_display(future_hours: list[HourPrice]) -> str
if h.dt == hour:
ret = h.permittance
break
return f"{str(int(ret*100))}%"
return f'{str(int(ret*100))}%'

0 comments on commit 1a26227

Please sign in to comment.