Skip to content

Commit

Permalink
Add of battery level information
Browse files Browse the repository at this point in the history
  • Loading branch information
cnico committed Nov 1, 2022
1 parent 79e569d commit 2ee9db6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


package = "flipr_api"
python_versions = ["3.9", "3.8", "3.7", "3.6"]
python_versions = ["3.10", "3.9", "3.8", "3.7", "3.6"]
nox.options.sessions = (
"pre-commit",
"safety",
Expand All @@ -21,7 +21,7 @@
)


@session(name="pre-commit", python="3.9")
@session(name="pre-commit", python="3.10")
def precommit(session: Session) -> None:
"""Lint using pre-commit."""
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
Expand All @@ -41,7 +41,7 @@ def precommit(session: Session) -> None:
session.run("pre-commit", *args)


@session(python="3.9")
@session(python="3.10")
def safety(session: Session) -> None:
"""Scan dependencies for insecure packages."""
requirements = session.poetry.export_requirements()
Expand Down Expand Up @@ -79,7 +79,7 @@ def coverage(session: Session) -> None:
# Do not use session.posargs unless this is the only session.
has_args = session.posargs and len(session._runner.manifest) == 1
# replace report by xml to generate an xml report for codecov.io
args = session.posargs if has_args else ["report"]
args = session.posargs if has_args else ["xml"]

session.install("coverage[toml]")

Expand All @@ -106,7 +106,7 @@ def xdoctest(session: Session) -> None:
session.run("python", "-m", "xdoctest", package, *args)


@session(name="docs-build", python="3.9")
@session(name="docs-build", python="3.10")
def docs_build(session: Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "docs/_build"]
Expand Down
1 change: 1 addition & 0 deletions src/flipr_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_pool_measure_latest(self, flipr_id: str) -> Dict[str, Any]:
"date_time": parse(json_resp["DateTime"]),
"ph_status": json_resp["PH"]["DeviationSector"],
"chlorine_status": json_resp["Desinfectant"]["DeviationSector"],
"battery": float(json_resp["Battery"]["Deviation"]),
}

def get_hub_state(self, hub_id: str) -> Dict[str, Any]:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,16 @@ def test_integration_simple(requests_mock) -> None: # type: ignore
red_ox = data["red_ox"]
chlorine = data["chlorine"]
ph = data["ph"]
battery = data["battery"]

print(
"Valeurs de la piscine : le {:s} temperature = {:.2f}, redox = {:.2f}, chlorine = {:.5f}, ph = {:.2f}".format(
"Valeurs de la piscine : le {:s} temperature = {:.2f}, redox = {:.2f}, chlorine = {:.5f}, ph = {:.2f}, battery= {:.2f}".format(
date_time.strftime("%Y-%m-%d %H:%M:%S"),
temperature,
red_ox,
chlorine,
ph,
battery,
)
)

Expand All @@ -203,6 +205,7 @@ def test_integration_simple(requests_mock) -> None: # type: ignore
assert chlorine == 0.31986785186370315
assert ph == 7.01
assert date_time.strftime("%Y-%m-%d %H:%M:%S") == "2021-02-01 07:40:21"
assert battery == 0.75

# Test hub id search
list_hub = client.search_hub_ids()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def test_integration_simple() -> None:

data = client.get_pool_measure_latest(FLIPR_ID)
print(
"Valeurs de la piscine : le {:s} temperature = {:.2f}, redox = {:.2f}, chlorine = {:.5f}, ph = {:.2f}, Alerte PH = {:s}, Alerte chlore = {:s}".format(
"Valeurs de la piscine : le {:s} temperature = {:.2f}, redox = {:.2f}, chlorine = {:.5f}, ph = {:.2f}, Alerte PH = {:s}, Alerte chlore = {:s}, Battery ={:.2f}".format(
data["date_time"].strftime("%Y-%m-%d %H:%M:%S"),
data["temperature"],
data["red_ox"],
data["chlorine"],
data["ph"],
data["ph_status"],
data["chlorine_status"],
data["battery"],
)
)

Expand All @@ -40,6 +41,7 @@ def test_integration_simple() -> None:
assert data["chlorine"] > 0
assert data["ph"] > 0
assert data["date_time"] is not None
assert data["battery"] > 0


@pytest.mark.skip("Not an automated test but an example of usage with real values.")
Expand Down

0 comments on commit 2ee9db6

Please sign in to comment.