Skip to content

Commit

Permalink
Utilisation de la nouvelle API serveur pour récupérer les valeurs. L'…
Browse files Browse the repository at this point in the history
…ancienne ne fonctionne plus...
  • Loading branch information
cnico committed Mar 10, 2023
1 parent cbcd577 commit c789eae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
20 changes: 10 additions & 10 deletions src/flipr_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ def get_pool_measure_latest(self, flipr_id: str) -> Dict[str, Any]:
chlorine_status : Alert status for chlorine value in : TooLow, MediumLow, Medium, MediumHigh, TooHigh
"""
resp = self._get_session().rest_request(
"GET", f"modules/{flipr_id}/survey/last"
"GET", f"modules/{flipr_id}/NewResume"
)
json_resp = resp.json()
if not json_resp:
raise FliprError(
f"Error : No data received for flipr {flipr_id} by the API. "
+ "You should test on flipr official app and contact goflipr if it is not working."
+ "You should test on flipr official app and contact goflipr if it is not working. Or perhaps API has changed :(."
)

# print("Réponse brute de get_pool_latest_values : " + str(json_resp))

return {
"temperature": float(json_resp["Temperature"]),
"ph": float(json_resp["PH"]["Value"]),
"chlorine": float(json_resp["Desinfectant"]["Value"]),
"red_ox": float(json_resp["OxydoReductionPotentiel"]["Value"]),
"date_time": parse(json_resp["DateTime"]),
"ph_status": json_resp["PH"]["DeviationSector"],
"chlorine_status": json_resp["Desinfectant"]["DeviationSector"],
"battery": float(json_resp["Battery"]["Deviation"] * 100),
"temperature": float(json_resp["Current"]["Temperature"]),
"ph": float(json_resp["Current"]["PH"]["Value"]),
"chlorine": float(json_resp["Current"]["Desinfectant"]["Value"]),
"red_ox": float(json_resp["Current"]["OxydoReductionPotentiel"]["Value"]),
"date_time": parse(json_resp["Current"]["DateTime"]),
"ph_status": json_resp["Current"]["PH"]["DeviationSector"],
"chlorine_status": json_resp["Current"]["Desinfectant"]["DeviationSector"],
"battery": float(json_resp["Current"]["Battery"]["Deviation"] * 100),
}

def get_hub_state(self, hub_id: str) -> Dict[str, Any]:
Expand Down
48 changes: 25 additions & 23 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,30 @@ def test_integration_simple(requests_mock) -> None: # type: ignore
],
)
requests_mock.get(
f"{FLIPR_API_URL}/modules/AB256C/survey/last",
f"{FLIPR_API_URL}/modules/AB256C/NewResume",
json={
"MeasureId": 405698,
"DateTime": "2021-02-01T07:40:21Z",
"Temperature": 10.0,
"PH": {
"Label": "PH",
"Message": "Parfait",
"Deviation": -0.47,
"Value": 7.01,
"DeviationSector": "Medium",
},
"OxydoReductionPotentiel": {"Label": "Potentiel Redox.", "Value": 474.0},
"Conductivity": {"Label": "Conductivité", "Level": "Low"},
"UvIndex": 0.0,
"Battery": {"Label": "Batterie", "Deviation": 0.75},
"Desinfectant": {
"Label": "Chlore",
"Message": "Trop faible",
"Deviation": -1.01,
"Value": 0.31986785186370315,
"DeviationSector": "TooLow",
"Current": {
"MeasureId": 405698,
"DateTime": "2021-02-01T07:40:21Z",
"Temperature": 10.0,
"PH": {
"Label": "PH",
"Message": "Parfait",
"Deviation": -0.47,
"Value": 7.01,
"DeviationSector": "Medium",
},
"OxydoReductionPotentiel": {"Label": "Potentiel Redox.", "Value": 474.0},
"Conductivity": {"Label": "Conductivité", "Level": "Low"},
"UvIndex": 0.0,
"Battery": {"Label": "Batterie", "Deviation": 0.75},
"Desinfectant": {
"Label": "Chlore",
"Message": "Trop faible",
"Deviation": -1.01,
"Value": 0.31986785186370315,
"DeviationSector": "TooLow",
},
},
},
)
Expand Down Expand Up @@ -267,7 +269,7 @@ def test_integration_fliprerror(requests_mock) -> None: # type: ignore

# This behaviour is a real one I encountered for an unknown reason of non functionning goflipr API.
requests_mock.get(
f"{FLIPR_API_URL}/modules/AB256C/survey/last",
f"{FLIPR_API_URL}/modules/AB256C/NewResume",
json={},
)

Expand All @@ -280,5 +282,5 @@ def test_integration_fliprerror(requests_mock) -> None: # type: ignore

assert (
str(error_info.value)
== "Error : No data received for flipr AB256C by the API. You should test on flipr official app and contact goflipr if it is not working."
== "Error : No data received for flipr AB256C by the API. You should test on flipr official app and contact goflipr if it is not working. Or perhaps API has changed :(."
)

0 comments on commit c789eae

Please sign in to comment.