Skip to content

Commit

Permalink
ajout limitation nombre d'heure de prevision
Browse files Browse the repository at this point in the history
  • Loading branch information
saniho committed Mar 14, 2024
1 parent 6b1307b commit 7cecd5a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
30 changes: 13 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions custom_components/apiMareeInfo/apiMareeInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ def getinformationport(self, jsondata=None, outfile=None, origine="MeteoMarine",
with open(outfile, 'w') as outfilev:
json.dump(jsondata, outfilev)
if origine == "MeteoMarine":
_LOGGER.error( jsondata )
self._nomDuPort = jsondata["contenu"]["marees"][0]['lieu']
self._dateCourante = jsondata["contenu"]["marees"][0]['datetime']
#_LOGGER.error( jsondata )
if len( jsondata["contenu"]["marees"]) == 0:
self._error = True
else:
self._nomDuPort = jsondata["contenu"]["marees"][0]['lieu']
self._dateCourante = jsondata["contenu"]["marees"][0]['datetime']
self._error = False
elif origine == "stormio":
if "station" in jsondata["meta"]:
self._nomDuPort = jsondata["meta"]["station"]['name']
Expand All @@ -166,6 +170,7 @@ def getinformationport(self, jsondata=None, outfile=None, origine="MeteoMarine",
a = {}
myMarees = {}
dicoPrevis = {}
#_LOGGER.error( "origine : %s / error : %s"%(origine, self._error))
if (origine == "MeteoMarine") and (not self._error):
j = 0
for maree in jsondata["contenu"]["marees"][:6]:
Expand Down
7 changes: 6 additions & 1 deletion custom_components/apiMareeInfo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def update(self, ):
self._myMaree.getinformationport(origine=self._origine)
else:
self._myMaree.getinformationport(origine="stormio", info={"stormkey": self._stormkey})
self._myMaree.setmaxhours(self._maxhours)
self._lastSynchro = datetime.datetime.now()

def getIdPort(self):
Expand Down Expand Up @@ -146,6 +147,7 @@ def _update(self):
try:
state, status_counts = self._sAM.getstatus()
except:
_LOGGER.error( "erreur dans getStatus()")
return
self._attributes = {ATTR_ATTRIBUTION: ""}
self._attributes.update(status_counts)
Expand All @@ -155,7 +157,10 @@ def _update(self):
def extra_state_attributes(self):
"""Return the state attributes."""
return self._attributes

@property
def device_state_attributes(self):
"""Return the state attributes."""
return self._attributes
@property
def icon(self):
"""Icon to use in the frontend."""
Expand Down
2 changes: 1 addition & 1 deletion file_20240314.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions testMareeInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def testPortMeteoMarine():

with open('./file_20240314.json') as f:
dataJson = json.load(f)
#dataJson = None
dataJson = None
from custom_components.apiMareeInfo import apiMareeInfo, sensorApiMaree

_myMaree = apiMareeInfo.ApiMareeInfo()
Expand All @@ -14,7 +14,8 @@ def testPortMeteoMarine():
lat, lng = "46.7711", "-2.05306"
_myMaree.setport(lat, lng)
#_myMaree.getinformationport(jsondata =dataJson)
_myMaree.getinformationport(outfile="file_20240314.json")
#_myMaree.getinformationport(outfile="file_20240314.json")
_myMaree.getinformationport()
_myMaree.setmaxhours(6)
#dataJson = None
_myMaree.getinformationport(dataJson)
Expand Down

0 comments on commit 7cecd5a

Please sign in to comment.