Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with main #183

Merged
merged 57 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b730c61
Bump black from 23.12.0 to 23.12.1 in /.github/workflows
dependabot[bot] Dec 26, 2023
621ce1a
Bump flake8 from 6.1.0 to 7.0.0 in /.github/workflows
dependabot[bot] Jan 5, 2024
54d2e56
Typo phase recovery
ic-dev21 Jan 10, 2024
156f5db
Update pyproject.toml
ic-dev21 Jan 10, 2024
1e49850
Merge branch 'dvd-dev:main' into main
ic-dev21 Jan 10, 2024
36e4688
Merge pull request #163 from ic-dev21/main
ic-dev21 Jan 10, 2024
882bcb3
Merge pull request #160 from dvd-dev/dependabot/pip/dot-github/workfl…
valleedelisle Jan 10, 2024
bfe82b3
Merge pull request #161 from dvd-dev/dependabot/pip/dot-github/workfl…
valleedelisle Jan 10, 2024
cdb4b6f
Update aresponses requirement from ^2.1.4 to ^3.0.0
dependabot[bot] Jan 12, 2024
96b6267
Changing master branch to main branch
valleedelisle Jan 14, 2024
fa1a986
Storing event update time
valleedelisle Jan 14, 2024
10af3d1
typo
valleedelisle Jan 14, 2024
b85f440
Adding an invalid attribute to event
valleedelisle Jan 14, 2024
25141db
Merge pull request #164 from dvd-dev/dependabot/pip/aresponses-tw-3.0.0
valleedelisle Jan 14, 2024
d5623c2
Update event.py
ic-dev21 Jan 18, 2024
e976b62
Essai de fix pour l'erreur de timezone
ic-dev21 Jan 19, 2024
a7b709f
Revert "Essai de fix pour l'erreur de timezone"
ic-dev21 Jan 19, 2024
7fdc3a3
Update event.py
ic-dev21 Jan 19, 2024
0b3f65b
Merge branch 'dvd-dev:main' into event_update_datetime
ic-dev21 Jan 19, 2024
b4a239f
Update event.py
ic-dev21 Jan 19, 2024
d423e58
Merge pull request #166 from ic-dev21/event_update_datetime
ic-dev21 Jan 19, 2024
28c2ced
Update pyproject.toml
ic-dev21 Jan 20, 2024
d74ba7b
Merge pull request #165 from dvd-dev/event_update_time
ic-dev21 Jan 20, 2024
0e5d218
Update event.py
ic-dev21 Jan 20, 2024
1bd2d0d
Ajout du model "43076" dans la liste JASCO
maxyvon Jan 26, 2024
ea56d88
Merge pull request #167 from maxyvon/main
ic-dev21 Jan 26, 2024
86a7ccd
Bump black from 23.12.1 to 24.1.0 in /.github/workflows
dependabot[bot] Jan 26, 2024
9d0347f
Ajout UNMONITORED_DEVICES pour utilitisation dans hilo/sensor.py
maxyvon Jan 26, 2024
42e5958
Changement de la valeur par défault du get_value de None à 'unknown'
maxyvon Jan 26, 2024
f182377
Merge pull request #168 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Jan 27, 2024
cc07ba6
Update pytest requirement from ^7.2.0 to ^8.0.0
dependabot[bot] Jan 29, 2024
ab86c7e
Bump black from 24.1.0 to 24.1.1 in /.github/workflows
dependabot[bot] Jan 29, 2024
d7f938f
Merge pull request #170 from maxyvon/UNMONITORED_DEVICES
valleedelisle Jan 31, 2024
587777d
Merge pull request #173 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Feb 2, 2024
b00ed0c
Merge pull request #172 from dvd-dev/dependabot/pip/pytest-tw-8.0.0
ic-dev21 Feb 2, 2024
5712d6c
Bump release-drafter/release-drafter from 5.25.0 to 6.0.0
dependabot[bot] Feb 2, 2024
eced3a1
Merge pull request #174 from dvd-dev/dependabot/github_actions/releas…
ic-dev21 Feb 3, 2024
94333de
Update types-pytz requirement from ^2023.3.0 to ^2024.1.0
dependabot[bot] Feb 5, 2024
5018157
Bump pip from 23.3.2 to 24.0 in /.github/workflows
dependabot[bot] Feb 5, 2024
07f5dc4
Merge pull request #176 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Feb 5, 2024
fb88d67
Merge pull request #175 from dvd-dev/dependabot/pip/types-pytz-tw-202…
ic-dev21 Feb 5, 2024
b62d241
Merge pull request #171 from maxyvon/default_get_value
ic-dev21 Feb 5, 2024
d6dd4a2
Bump up version
ic-dev21 Feb 6, 2024
2d988b9
Merge branch 'dvd-dev:main' into main
ic-dev21 Feb 6, 2024
b1cd4a3
Merge pull request #177 from ic-dev21/main
ic-dev21 Feb 6, 2024
e7cbb47
Move seasons from automation to challenge
dave-hilo Feb 6, 2024
9f9c277
lint
dave-hilo Feb 6, 2024
3620772
Merge pull request #178 from dave-hilo/feature/seasons-new-url
ic-dev21 Feb 6, 2024
0d1ec4e
Update pyproject.toml
ic-dev21 Feb 6, 2024
45330d9
Merge pull request #179 from ic-dev21/main
ic-dev21 Feb 6, 2024
81490ba
Bump pre-commit from 3.6.0 to 3.6.1 in /.github/workflows
dependabot[bot] Feb 12, 2024
a0d9dc4
Merge pull request #180 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Feb 12, 2024
06dce31
Bump black from 24.1.1 to 24.2.0 in /.github/workflows
dependabot[bot] Feb 13, 2024
964e3e3
Merge pull request #181 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Feb 13, 2024
01e1e22
Bump pre-commit from 3.6.1 to 3.6.2 in /.github/workflows
dependabot[bot] Feb 19, 2024
74a1bc7
Merge pull request #182 from dvd-dev/dependabot/pip/dot-github/workfl…
ic-dev21 Feb 19, 2024
25ad5f1
Merge branch 'main' into feature/new-auth
dave-hilo Feb 28, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pip==23.3.2
black==23.12.1
pre-commit==3.6.0
flake8==6.1.0
pip==24.0
black==24.2.0
pre-commit==3.6.2
flake8==7.0.0
reorder-python-imports==3.12.0
1 change: 0 additions & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- master

jobs:
labeler:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ on:
push:
branches:
- main
- master
jobs:
draft_release:
name: Release Drafter
runs-on: ubuntu-latest
steps:
- name: Run release-drafter
uses: release-drafter/release-drafter@v5.25.0
uses: release-drafter/release-drafter@v6.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- master
- dev
pull_request:
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:
- id: no-commit-to-branch
args:
- --branch=dev
- --branch=master
- --branch=main
# - repo: https://github.com/PyCQA/pydocstyle
# rev: 5.0.2
# hooks:
Expand Down
10 changes: 8 additions & 2 deletions pyhilo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ANDROID_CLIENT_HOSTNAME,
ANDROID_CLIENT_POST,
API_AUTOMATION_ENDPOINT,
API_CHALLENGE_ENDPOINT,
API_EVENTS_ENDPOINT,
API_GD_SERVICE_ENDPOINT,
API_HOSTNAME,
Expand Down Expand Up @@ -252,6 +253,7 @@ def _get_url(
gd: bool = False,
drms: bool = False,
events: bool = False,
challenge: bool = False,
) -> str:
"""Generate a path to the requested endpoint.

Expand All @@ -263,6 +265,8 @@ def _get_url(
:type gd: bool, optional
:param drms: Whether or not we should prepend the path with DRMS path, defaults to False
:type drms: bool, optional
:param challenge: Whether or not we should prepend the path with challenge path, defaults to False
:type challenge: bool, optional
:return: Path to the requested endpoint
:rtype: str
"""
Expand All @@ -273,6 +277,8 @@ def _get_url(
base += "/DRMS"
if events:
base = API_EVENTS_ENDPOINT + API_NOTIFICATIONS_ENDPOINT
if challenge:
base = API_CHALLENGE_ENDPOINT
url = base + "/Locations/" + str(location_id)
if endpoint:
url += "/" + str(endpoint)
Expand Down Expand Up @@ -590,7 +596,7 @@ async def get_gd_events(

async def get_seasons(self, location_id: int) -> dict[str, Any]:
"""This will return the rewards and current season total
https://apim.hiloenergie.com/Automation/v1/api/DRMS/Locations/XXXX/Seasons
https://api.hiloenergie.com/challenge/v1/api/Locations/XXXX/Seasons
[
{
"season": 2021,
Expand All @@ -607,7 +613,7 @@ async def get_seasons(self, location_id: int) -> dict[str, Any]:
}
]
"""
url = self._get_url("Seasons", location_id, drms=True)
url = self._get_url("Seasons", location_id, challenge=True)
return cast(dict[str, Any], await self.async_request("get", url))

async def get_gateway(self, location_id: int) -> dict[str, Any]:
Expand Down
7 changes: 7 additions & 0 deletions pyhilo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
API_HOSTNAME: Final = "api.hiloenergie.com"
API_END: Final = "v1/api"
API_AUTOMATION_ENDPOINT: Final = f"/Automation/{API_END}"
API_CHALLENGE_ENDPOINT: Final = f"/challenge/{API_END}"
API_GD_SERVICE_ENDPOINT: Final = f"/GDService/{API_END}"
API_NOTIFICATIONS_ENDPOINT: Final = "/Notifications"
API_EVENTS_ENDPOINT: Final = "/Notifications"
Expand Down Expand Up @@ -239,6 +240,7 @@

JASCO_MODELS: Final = [
"43082",
"43076",
"43078",
"43100",
"46199",
Expand All @@ -255,3 +257,8 @@
"43100",
"45853",
]

UNMONITORED_DEVICES: Final = [
"43076",
"43100",
]
4 changes: 3 additions & 1 deletion pyhilo/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from datetime import datetime
from typing import TYPE_CHECKING, Any, Dict, Union, cast

from homeassistant.const import STATE_UNKNOWN

from pyhilo.const import (
HILO_DEVICE_ATTRIBUTES,
HILO_LIST_ATTRIBUTES,
Expand Down Expand Up @@ -150,7 +152,7 @@ def has_attribute(self, attr: str) -> bool:
return next((True for k in self.supported_attributes if k.attr == attr), False)

def get_value(
self, attribute: str, default: Union[str, int, float, None] = None
self, attribute: str, default: Union[str, int, float, None] = STATE_UNKNOWN
) -> Any:
attr = self.get_attribute(attribute)
return attr.value if attr else default
Expand Down
31 changes: 29 additions & 2 deletions pyhilo/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Event object """
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import re
from typing import Any, cast

Expand Down Expand Up @@ -38,8 +38,12 @@ def __init__(self, **event: dict[str, Any]):
self.allowed_kWh: float = round(allowed_wH / 1000, 2)
self.used_kWh: float = round(used_wH / 1000, 2)
self.used_percentage: float = 0
self.last_update = datetime.now(timezone.utc).astimezone()
if allowed_wH > 0:
self.used_percentage = round(used_wH / allowed_wH * 100, 2)
self._phase_time_mapping = {
"pre_heat": "preheat",
}
self.dict_items = [
"event_id",
"participating",
Expand All @@ -52,6 +56,7 @@ def __init__(self, **event: dict[str, Any]):
"allowed_kWh",
"used_kWh",
"used_percentage",
"last_update",
]

def as_dict(self) -> dict[str, Any]:
Expand Down Expand Up @@ -96,6 +101,28 @@ def appreciation(self, hours: int) -> datetime:
def pre_cold(self, hours: int) -> datetime:
return self._create_phases(hours, "pre_cold", "appreciation")

@property
def invalid(self) -> bool:
return cast(
bool,
(
self.current_phase_times
and self.last_update < self.current_phase_times["start"]
),
)

@property
def current_phase_times(self) -> dict[str, datetime]:
if self.state in ["completed", "off", "scheduled", "unknown"]:
return {}
phase_timestamp = self._phase_time_mapping.get(self.state, self.state)
phase_start = f"{phase_timestamp}_start"
phase_end = f"{phase_timestamp}_end"
return {
"start": getattr(self, phase_start),
"end": getattr(self, phase_end),
}

@property
def state(self) -> str:
now = datetime.now(self.preheat_start.tzinfo)
Expand All @@ -111,7 +138,7 @@ def state(self) -> str:
return "reduction"
elif self.recovery_start <= now < self.recovery_end:
return "recovery"
elif now <= self.recovery_end:
elif now >= self.recovery_end:
return "completed"
elif self.progress:
return self.progress
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exclude = ".venv/.*"

[tool.poetry]
name = "python-hilo"
version = "2023.12.02"
version = "2024.2.2"
description = "A Python3, async interface to the Hilo API"
readme = "README.md"
authors = ["David Vallee Delisle <[email protected]>"]
Expand Down Expand Up @@ -77,14 +77,14 @@ websockets = ">=8.1,<12.0"

[tool.poetry.dev-dependencies]
Sphinx = "^7.1.2"
aresponses = "^2.1.4"
aresponses = "^3.0.0"
asynctest = "^0.13.0"
pre-commit = "^3.2.2"
pytest = "^7.2.0"
pytest = "^8.0.0"
pytest-aiohttp = "^1.0.4"
pytest-cov = "^4.0.0"
sphinx-rtd-theme = "^2.0.0"
types-pytz = "^2023.3.0"
types-pytz = "^2024.1.0"

[tool.pylint.BASIC]
expected-line-ending-format = "LF"
Expand Down