Hydro-Quebec-API-Wrapper 4.4.0__tar.gz → 4.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0/Hydro_Quebec_API_Wrapper.egg-info}/PKG-INFO +1 -1
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/Hydro_Quebec_API_Wrapper.egg-info/SOURCES.txt +2 -1
- {hydro_quebec_api_wrapper-4.4.0/Hydro_Quebec_API_Wrapper.egg-info → hydro_quebec_api_wrapper-4.5.0}/PKG-INFO +1 -1
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/client.py +73 -1
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/consts.py +8 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/webuser.py +4 -0
- hydro_quebec_api_wrapper-4.5.0/tests/unit/test_portal_unavailability.py +132 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.coveragerc +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.devcontainer/Dockerfile +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.devcontainer/devcontainer.json +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.flake8 +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.github/scripts/home_assistant_versions.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.github/workflows/ci.yml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.github/workflows/release.yml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.gitignore +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.gitlab-ci.yml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.pre-commit-config.yaml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.pylintrc +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/Hydro_Quebec_API_Wrapper.egg-info/dependency_links.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/Hydro_Quebec_API_Wrapper.egg-info/entry_points.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/Hydro_Quebec_API_Wrapper.egg-info/requires.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/Hydro_Quebec_API_Wrapper.egg-info/top_level.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/LICENSE +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/MANIFEST.in +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/README.md +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/config.default.yaml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/conflict_test_requirements.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/Makefile +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/make.bat +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/_static/custom.css +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/_static/hydroqc-logo-128.png +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/_static/hydroqc-logo.svg +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/conf.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/external/description-des-codes-interruption.pdf +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/index.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.contract.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.hydro_api.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.peak.cpc.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.peak.dpc.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.peak.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.types.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/modules.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/todo.rst +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/examples/hydro.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/account.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/common.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_d.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_d_cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_dt.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_m.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_m_gdp.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_residential.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/outage.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/customer.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/diagnostic.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/error.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/cache.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/mfa.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/logger.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/basepeak.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/basepeakhandler.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/handler.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/peak.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/handler.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/peak.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/public_client.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/py.typed +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/timerange.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/account.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/common.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/consump.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/contract.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/dt.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/types/outage.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/utils.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/logo/hydroqc-logo-128.png +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/logo/hydroqc-logo.svg +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/pyproject.toml +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/renovate.json5 +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/setup.cfg +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/test_requirements.txt +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/conftest.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_common.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_d.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_d_cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_dt.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_m.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_m_gdp.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/test_basic.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/test_timerange.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/tools.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/test_login_flow.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/test_mfa.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/test_mobile_client.py +0 -0
- {hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tox.ini +0 -0
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/client.py
RENAMED
|
@@ -53,6 +53,9 @@ from hydroqc.hydro_api.consts import (
|
|
|
53
53
|
OPEN_DATA_PEAK_URL,
|
|
54
54
|
OUTAGES,
|
|
55
55
|
PERIOD_DATA_URL,
|
|
56
|
+
PORTAL_UNAVAILABILITY_DATE_FORMAT,
|
|
57
|
+
PORTAL_UNAVAILABILITY_SERVICES,
|
|
58
|
+
PORTAL_UNAVAILABILITY_URL,
|
|
56
59
|
PORTRAIT_URL,
|
|
57
60
|
RELATION_URL,
|
|
58
61
|
REQUESTS_TIMEOUT,
|
|
@@ -406,8 +409,77 @@ class HydroClient:
|
|
|
406
409
|
await self._session.close()
|
|
407
410
|
self._session = None
|
|
408
411
|
|
|
412
|
+
async def get_portal_unavailability(self) -> dict[str, str] | None:
|
|
413
|
+
"""Return the planned unavailability window in effect, if any.
|
|
414
|
+
|
|
415
|
+
Reads the feed the Espace client uses to show its maintenance page. The
|
|
416
|
+
result holds ``service``, ``from``, ``to`` (Hydro-Quebec local time) and
|
|
417
|
+
the ``messages_fr``/``messages_en`` HTML. ``None`` when no window covers
|
|
418
|
+
the current time or when the feed cannot be read.
|
|
419
|
+
"""
|
|
420
|
+
await self._get_httpsession()
|
|
421
|
+
try:
|
|
422
|
+
# Same cache buster as the Espace client, so an early end shows up.
|
|
423
|
+
params = {"date": str(int(datetime.now().timestamp() * 1000))}
|
|
424
|
+
response = await self.http_request(
|
|
425
|
+
PORTAL_UNAVAILABILITY_URL, "get", params=params, status=None
|
|
426
|
+
)
|
|
427
|
+
if response.status != 200:
|
|
428
|
+
self._logger.debug(
|
|
429
|
+
"Unavailability feed answered HTTP %s", response.status
|
|
430
|
+
)
|
|
431
|
+
return None
|
|
432
|
+
feed = await response.json(content_type=None)
|
|
433
|
+
except (HydroQcError, aiohttp.ClientError, asyncio.TimeoutError, ValueError):
|
|
434
|
+
self._logger.debug("Could not read the unavailability feed", exc_info=True)
|
|
435
|
+
return None
|
|
436
|
+
if not isinstance(feed, dict):
|
|
437
|
+
return None
|
|
438
|
+
|
|
439
|
+
now = datetime.now(EST_TIMEZONE)
|
|
440
|
+
for service in PORTAL_UNAVAILABILITY_SERVICES:
|
|
441
|
+
windows = feed.get(service)
|
|
442
|
+
if not isinstance(windows, list):
|
|
443
|
+
continue
|
|
444
|
+
for window in windows:
|
|
445
|
+
try:
|
|
446
|
+
start = EST_TIMEZONE.localize(
|
|
447
|
+
datetime.strptime(
|
|
448
|
+
window["from"], PORTAL_UNAVAILABILITY_DATE_FORMAT
|
|
449
|
+
)
|
|
450
|
+
)
|
|
451
|
+
end = EST_TIMEZONE.localize(
|
|
452
|
+
datetime.strptime(
|
|
453
|
+
window["to"], PORTAL_UNAVAILABILITY_DATE_FORMAT
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
except (KeyError, TypeError, ValueError):
|
|
457
|
+
continue
|
|
458
|
+
if start <= now < end:
|
|
459
|
+
return {
|
|
460
|
+
"service": service,
|
|
461
|
+
"from": window["from"],
|
|
462
|
+
"to": window["to"],
|
|
463
|
+
"messages_fr": str(window.get("messages_fr", "")),
|
|
464
|
+
"messages_en": str(window.get("messages_en", "")),
|
|
465
|
+
}
|
|
466
|
+
return None
|
|
467
|
+
|
|
409
468
|
async def check_portal_status(self) -> bool:
|
|
410
|
-
"""Check if Hydro Quebec portal is UP.
|
|
469
|
+
"""Check if Hydro Quebec portal is UP.
|
|
470
|
+
|
|
471
|
+
The portal page keeps answering 200 during a planned maintenance, so the
|
|
472
|
+
unavailability feed is checked first.
|
|
473
|
+
"""
|
|
474
|
+
if (unavailability := await self.get_portal_unavailability()) is not None:
|
|
475
|
+
self._logger.info(
|
|
476
|
+
"Hydro Quebec announces a maintenance of %s from %s to %s",
|
|
477
|
+
unavailability["service"],
|
|
478
|
+
unavailability["from"],
|
|
479
|
+
unavailability["to"],
|
|
480
|
+
)
|
|
481
|
+
return False
|
|
482
|
+
|
|
411
483
|
# Get http session
|
|
412
484
|
await self._get_httpsession()
|
|
413
485
|
self._logger.info("Checking if the Hydro Quebec portal is UP")
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/consts.py
RENAMED
|
@@ -196,3 +196,11 @@ AUTH_CLIENTS = {
|
|
|
196
196
|
api_channel="mobile",
|
|
197
197
|
),
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
# Maintenance windows the Espace client reads (indisponibiliteUrl in its config/app.json).
|
|
201
|
+
PORTAL_UNAVAILABILITY_URL = (
|
|
202
|
+
"https://clientele-statique.solutions.hydroquebec.com/config/indispo/"
|
|
203
|
+
"indisponibilites.json"
|
|
204
|
+
)
|
|
205
|
+
PORTAL_UNAVAILABILITY_SERVICES = ("libreService", "appMobileAuthentifiee")
|
|
206
|
+
PORTAL_UNAVAILABILITY_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
|
@@ -65,6 +65,10 @@ class WebUser:
|
|
|
65
65
|
"""Check if the Hydro Quebec website/portal is available."""
|
|
66
66
|
return await self._hydro_client.check_portal_status()
|
|
67
67
|
|
|
68
|
+
async def get_hq_portal_unavailability(self) -> dict[str, str] | None:
|
|
69
|
+
"""Return the planned Hydro Quebec unavailability in effect, if any."""
|
|
70
|
+
return await self._hydro_client.get_portal_unavailability()
|
|
71
|
+
|
|
68
72
|
async def login(self) -> LoginStatus:
|
|
69
73
|
"""Login to Hydroquebec website.
|
|
70
74
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Check the planned unavailability feed used by the portal status."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from hydroqc.hydro_api import client as client_module
|
|
12
|
+
from hydroqc.hydro_api.consts import IS_HYDRO_PORTAL_UP_URL, PORTAL_UNAVAILABILITY_URL
|
|
13
|
+
from hydroqc.utils import EST_TIMEZONE
|
|
14
|
+
from tests.unit.test_mfa import FakeResponse, ScriptedTransport, build_client
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _feed(service: str = "appMobileAuthentifiee") -> str:
|
|
18
|
+
"""Return a feed with one window on 2026-11-07 18:00 to 2026-11-08 18:00."""
|
|
19
|
+
return json.dumps(
|
|
20
|
+
{
|
|
21
|
+
service: [
|
|
22
|
+
{
|
|
23
|
+
"from": "2026-11-07 18:00:00",
|
|
24
|
+
"to": "2026-11-08 18:00:00",
|
|
25
|
+
"messages_fr": "<h2>Travaux</h2>",
|
|
26
|
+
"messages_en": "<h2>Maintenance</h2>",
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _freeze(monkeypatch: pytest.MonkeyPatch, when: str | datetime) -> None:
|
|
34
|
+
"""Make the client see ``when`` (Hydro-Quebec local time, or aware) as now."""
|
|
35
|
+
frozen = (
|
|
36
|
+
when
|
|
37
|
+
if isinstance(when, datetime)
|
|
38
|
+
else EST_TIMEZONE.localize(datetime.strptime(when, "%Y-%m-%d %H:%M"))
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
class FrozenDatetime(datetime):
|
|
42
|
+
"""Datetime whose now() is fixed."""
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def now(cls, tz: Any = None) -> Any:
|
|
46
|
+
"""Return the frozen time."""
|
|
47
|
+
return frozen.astimezone(tz) if tz else frozen
|
|
48
|
+
|
|
49
|
+
monkeypatch.setattr(client_module, "datetime", FrozenDatetime)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
53
|
+
@pytest.mark.parametrize("service", ["libreService", "appMobileAuthentifiee"])
|
|
54
|
+
async def test_portal_down_during_window(
|
|
55
|
+
monkeypatch: pytest.MonkeyPatch, service: str
|
|
56
|
+
) -> None:
|
|
57
|
+
"""A window covering now reports the portal down without probing it."""
|
|
58
|
+
_freeze(monkeypatch, "2026-11-07 20:00")
|
|
59
|
+
transport = ScriptedTransport()
|
|
60
|
+
transport.add("get", PORTAL_UNAVAILABILITY_URL, FakeResponse(text=_feed(service)))
|
|
61
|
+
client = build_client(transport)
|
|
62
|
+
|
|
63
|
+
window = await client.get_portal_unavailability()
|
|
64
|
+
assert window is not None
|
|
65
|
+
assert window["service"] == service
|
|
66
|
+
assert window["to"] == "2026-11-08 18:00:00"
|
|
67
|
+
assert await client.check_portal_status() is False
|
|
68
|
+
assert not transport.called(IS_HYDRO_PORTAL_UP_URL)
|
|
69
|
+
# The feed is fetched with a cache buster, like the Espace client does.
|
|
70
|
+
feed_call = next(c for c in transport.calls if PORTAL_UNAVAILABILITY_URL in c[1])
|
|
71
|
+
assert feed_call[2]["params"]["date"].isdigit()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
75
|
+
@pytest.mark.parametrize("when", ["2026-11-07 17:59", "2026-11-08 18:00"])
|
|
76
|
+
async def test_portal_probed_outside_window(
|
|
77
|
+
monkeypatch: pytest.MonkeyPatch, when: str
|
|
78
|
+
) -> None:
|
|
79
|
+
"""Outside the window the portal page is probed as before."""
|
|
80
|
+
_freeze(monkeypatch, when)
|
|
81
|
+
transport = ScriptedTransport()
|
|
82
|
+
transport.add("get", PORTAL_UNAVAILABILITY_URL, FakeResponse(text=_feed()))
|
|
83
|
+
transport.add("get", IS_HYDRO_PORTAL_UP_URL, FakeResponse())
|
|
84
|
+
client = build_client(transport)
|
|
85
|
+
|
|
86
|
+
assert await client.get_portal_unavailability() is None
|
|
87
|
+
assert await client.check_portal_status() is True
|
|
88
|
+
assert transport.called(IS_HYDRO_PORTAL_UP_URL)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
92
|
+
@pytest.mark.parametrize(("utc_hour", "down"), [(21, False), (22, True)])
|
|
93
|
+
async def test_summer_window_uses_daylight_time(
|
|
94
|
+
monkeypatch: pytest.MonkeyPatch, utc_hour: int, down: bool
|
|
95
|
+
) -> None:
|
|
96
|
+
"""A July 18:00 start is 22:00 UTC (EDT, -04:00), not 23:00 UTC (EST)."""
|
|
97
|
+
_freeze(monkeypatch, datetime(2026, 7, 15, utc_hour, 0, tzinfo=timezone.utc))
|
|
98
|
+
feed = (
|
|
99
|
+
_feed().replace("2026-11-07", "2026-07-15").replace("2026-11-08", "2026-07-16")
|
|
100
|
+
)
|
|
101
|
+
transport = ScriptedTransport()
|
|
102
|
+
transport.add("get", PORTAL_UNAVAILABILITY_URL, FakeResponse(text=feed))
|
|
103
|
+
client = build_client(transport)
|
|
104
|
+
|
|
105
|
+
assert (await client.get_portal_unavailability() is not None) is down
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
109
|
+
@pytest.mark.parametrize(
|
|
110
|
+
"body", ["not json", "[]", '{"libreService": [{"from": "x"}]}']
|
|
111
|
+
)
|
|
112
|
+
async def test_unreadable_feed_falls_back(body: str) -> None:
|
|
113
|
+
"""A feed that cannot be used does not block the usual probe."""
|
|
114
|
+
transport = ScriptedTransport()
|
|
115
|
+
transport.add("get", PORTAL_UNAVAILABILITY_URL, FakeResponse(text=body))
|
|
116
|
+
transport.add("get", IS_HYDRO_PORTAL_UP_URL, FakeResponse())
|
|
117
|
+
client = build_client(transport)
|
|
118
|
+
|
|
119
|
+
assert await client.get_portal_unavailability() is None
|
|
120
|
+
assert await client.check_portal_status() is True
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
124
|
+
async def test_feed_http_error_falls_back() -> None:
|
|
125
|
+
"""A feed answering an error status falls back to the usual probe."""
|
|
126
|
+
transport = ScriptedTransport()
|
|
127
|
+
transport.add("get", PORTAL_UNAVAILABILITY_URL, FakeResponse(status=404))
|
|
128
|
+
transport.add("get", IS_HYDRO_PORTAL_UP_URL, FakeResponse())
|
|
129
|
+
client = build_client(transport)
|
|
130
|
+
|
|
131
|
+
assert await client.get_portal_unavailability() is None
|
|
132
|
+
assert await client.check_portal_status() is True
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.devcontainer/devcontainer.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/.github/workflows/release.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/conflict_test_requirements.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/_static/custom.css
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/hydroqc.rst
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/docs/source/reference/modules.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/common.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_d.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_d_cpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_dpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_dt.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_m.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/contract_m_gdp.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/contract/outage.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/hydro_api/cache.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/basepeakhandler.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/consts.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/cpc/handler.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/consts.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/hydroqc/peak/dpc/handler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_d.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_d_cpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_dpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_dt.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_m.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/subtest_contract_m_gdp.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/test_login_flow.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.4.0 → hydro_quebec_api_wrapper-4.5.0}/tests/unit/test_mobile_client.py
RENAMED
|
File without changes
|
|
File without changes
|