Skip to content

Commit

Permalink
message erreur en francais
Browse files Browse the repository at this point in the history
config flow
  • Loading branch information
saniho committed Dec 26, 2020
1 parent 6005e6e commit d90e234
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 34 deletions.
21 changes: 10 additions & 11 deletions custom_components/apiEnedis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
CONF_SCAN_INTERVAL,
EVENT_HOMEASSISTANT_STARTED,
)
#from integrationhelper.const import CC_STARTUP_VERSION

VERSION="1.0"
ISSUE_URL="https://github.com/saniho/apiEnedis"

from homeassistant.core import CoreState, callback
from homeassistant.exceptions import ConfigEntryNotReady
Expand All @@ -28,8 +24,10 @@
HP_COST,
HC_COST,
DEFAULT_SCAN_INTERVAL,
DEFAULT_SENSOR_INTERVAL,
myENEDIS_SERVICE,
__VERSION__,
CONF_DELAY,
)
_LOGGER = logging.getLogger(__name__)

Expand All @@ -52,7 +50,8 @@ async def _async_setup_entry(hass, config_entry):
async def _enable_scheduled_myEnedis(*_):
"""Activate the data update coordinator."""
coordinator.update_interval = timedelta(
seconds=config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
#seconds=config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
seconds=DEFAULT_SCAN_INTERVAL
)
await coordinator.async_refresh()

Expand Down Expand Up @@ -157,8 +156,8 @@ async def async_set_options(self):
CONF_SCAN_INTERVAL: data.pop(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL),
CONF_TOKEN: data.pop(CONF_TOKEN, ""),
CONF_CODE: str(data.pop(CONF_CODE, "")),
HP_COST: str(data.pop(HP_COST, "")),
HC_COST: str(data.pop(HC_COST, "")),
HP_COST: str(data.pop(HP_COST, "0.0")),
HC_COST: str(data.pop(HC_COST, "0.0")),
}
self.hass.config_entries.async_update_entry(
self.config_entry, data=data, options=options
Expand All @@ -170,19 +169,19 @@ def update_MyEnedis(self):
_LOGGER.info("update_MyEnedis")
if (not self.myEnedis.getInit()):
_LOGGER.info("getInit()")
delai_interval = 1800 # delai de rafraichissement de l'appel API
delai_interval = CONF_DELAY # delai de rafraichissement de l'appel API
heuresCreusesCh = "[]"
heuresCreuses = eval(heuresCreusesCh)
HC_Cost_key = "hc_cout"
HP_Cost_key = "hp_cout"
if (HC_Cost_key not in self.config_entry.options.keys()):
HCCost = float("0.0")
else:
HCCost = float(self.config_entry.options[HC_Cost_key])
HCCost = float(self.config_entry.options.get(HC_Cost_key, "0.0"))
if (HP_Cost_key not in self.config_entry.options.keys()):
HPCost = float("0.0")
else:
HPCost = float(self.config_entry.options[HP_Cost_key])
HPCost = float(self.config_entry.options.get(HP_Cost_key, "0.0"))
token, code = self.config_entry.options['token'], self.config_entry.options['code']
_LOGGER.info("options - proc -- %s %s %s %s" %(token, code, HPCost, HCCost))
myDataEnedis = myEnedis.myEnedis(token, code, delai_interval, \
Expand Down Expand Up @@ -224,7 +223,7 @@ async def options_updated_listener(hass, entry):

_LOGGER.info("options_updated_listener ")
hass.data[DOMAIN].update_interval = timedelta(
seconds=60#entry.options[CONF_SCAN_INTERVAL]
seconds=DEFAULT_SENSOR_INTERVAL
)
await hass.data[DOMAIN].async_request_refresh()
_LOGGER.info("options_updated_listener - done -- ")
4 changes: 2 additions & 2 deletions custom_components/apiEnedis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ async def async_step_init(self, user_input=None):
vol.Optional(
HC_COST,
default=self.config_entry.options.get(
HC_COST, "0.08"
HC_COST, "0.0"
),
): cv.string,

vol.Optional(
HP_COST,
default=self.config_entry.options.get(
HP_COST, "0.01"
HP_COST, "0.0"
),
): cv.string
}
Expand Down
12 changes: 7 additions & 5 deletions custom_components/apiEnedis/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Constants """

#myENEDIS_SERVICE = "myenedisservice"

ISSUE_URL="https://github.com/saniho/apiEnedis/issues"
myENEDIS_SERVICE = "myEnedis"
# nom du repertoire
DOMAIN = "myEnedis"
Expand All @@ -12,13 +13,14 @@
# Configuration
CONF_TOKEN = "token"
CONF_CODE = "code"
CONF_SCAN_INTERVAL = "conf_scan_interval"
CONF_SCAN_INTERVAL = "conf_scan_interval" # 60 secondes verifications du coordinator

HP_COST = "hp_cout"
HC_COST = "hc_cout"

#DEFAULT_SCAN_INTERVAL = 1800
DEFAULT_SCAN_INTERVAL = 120
CONF_DELAY = 60 * 60 * 6 # verification enedis toutes les 6 heures
DEFAULT_SCAN_INTERVAL = 60*5 # verification enedis toutes les 5 minutes, si dernier ok, alors verif selon conf_delay
DEFAULT_SENSOR_INTERVAL = 60 # 60 secondes verifications du coordinator


__VERSION__ = "1.0.5.5c"
__VERSION__ = "1.0.5.5d"
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "myEnedis",
"name": "myEnedis sensor",
"documentation": "",
"documentation": "https://github.com/saniho/apiEnedis/",
"config_flow": true,
"requirements": [
],
Expand Down
7 changes: 2 additions & 5 deletions custom_components/apiEnedis/myEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, token, PDL_ID, delai = 3600, heuresCreuses = None, \
self._heuresCreuses = heuresCreuses
self._heuresCreusesCost = heuresCreusesCost
self._heuresPleinesCost = heuresPleinesCost
self._contract = None #{'subscribed_power':"", 'offpeak_hours':""}
self._contract = None
self._HC, self._HP = 0, 0
self._interval_length = 1
self._updateRealise = False
Expand All @@ -46,10 +46,8 @@ def __init__(self, token, PDL_ID, delai = 3600, heuresCreuses = None, \
if ( log == None ):
self._log = logging.getLogger(__nameMyEnedis__)
self._log.setLevel(logging.DEBUG)
#self._log.setLevel(logging.WARNING)
else:
self._log = log
#self._log.setLevel(logging.DEBUG)
pass

def myLog(self, message):
Expand All @@ -75,7 +73,6 @@ def post_and_get_json(self, url, params=None, data=None, headers=None):
#response = session.post(url, params=params, data=json.dumps(data), headers=headers)
response = session.post(url, params=params, data=json.dumps(data), headers=headers, timeout=30)
response.raise_for_status()
# async http ?
return response.json()
except requests.exceptions.HTTPError as error:
self.myLogWarning("Error JSON : %s "%(response.text))
Expand Down Expand Up @@ -636,7 +633,7 @@ def updateErrorLastCall(self, errorMessage):
def getDelai(self):
return self._delai
def getDelaiIsGood(self):
self.myLog("TimeLastCall : %s" %(self.getTimeLastCall()))
self.myLogWarning("TimeLastCall : %s" %(self.getTimeLastCall()))
ecartOk = ( datetime.datetime.now() - self.getTimeLastCall()).seconds > self.getDelai()
return ecartOk

Expand Down
14 changes: 5 additions & 9 deletions custom_components/apiEnedis/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_NAME,
CONF_DELAY,
CONF_SCAN_INTERVAL,
ATTR_ATTRIBUTION,
)
Expand Down Expand Up @@ -38,6 +37,7 @@
HC_COST,
HP_COST,
DEFAULT_SCAN_INTERVAL,
CONF_DELAY,
__VERSION__,
)

Expand All @@ -50,8 +50,6 @@
DEFAUT_HEURES_CREUSES = "[]"
DEFAUT_COST = "0.0"
HEURES_CREUSES = "heures_creuses"
#HC_COUT = "hc_cout"
#HP_COUT = "hp_cout"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -193,9 +191,9 @@ def update():

if 'yesterday' not in self._attributes.keys() and 'yesterday_production' not in self._attributes.keys(): # pas plutot la key à checker ??
self._state = state.state
_LOGGER.warning("*** / / / \ \ \ *** mise a jour state precedent %s " % (self._state))
#_LOGGER.warning("*** / / / \ \ \ *** mise a jour state precedent %s " % (self._state))
self._attributes = state.attributes
_LOGGER.warning("*** / / / \ \ \ *** mise a jour attributes precedent %s " %( self._attributes ))
#_LOGGER.warning("*** / / / \ \ \ *** mise a jour attributes precedent %s " %( self._attributes ))
#on sauvegarde les elements pour les reprendre si errot
self.setLastAttributes()
self.setLastState()
Expand All @@ -206,7 +204,6 @@ def _update_state(self):

#if self.coordinator.data:
# self._state = self.coordinator.data["ping"]
import random
self._attributes = {ATTR_ATTRIBUTION: "" }
status_counts, state = self._myDataEnedis.myEnedis.getStatus()
self._attributes.update(status_counts)
Expand Down Expand Up @@ -275,7 +272,6 @@ def unit_of_measurement(self):

def _update(self):
"""Update device state."""

self._attributes = {ATTR_ATTRIBUTION: "" }
self._myDataEnedis.updateManagerSensor()
status_counts, state = self._myDataEnedis.getStatus()
Expand Down Expand Up @@ -303,9 +299,9 @@ async def async_added_to_hass(self) -> None:
# si la clef yesterday est disponible dans l'element courant, alors c'est que l'on a eut une mise à jour
if 'yesterday' not in self._attributes.keys() and 'yesterday_production' not in self._attributes.keys(): # pas plutot la key à checker ??
self._state = state.state
_LOGGER.warning("*** / / / \ \ \ *** mise a jour state precedent %s " % (self._state))
#_LOGGER.warning("*** / / / \ \ \ *** mise a jour state precedent %s " % (self._state))
self._attributes = state.attributes
_LOGGER.warning("*** / / / \ \ \ *** mise a jour attributes precedent %s " %( self._attributes ))
#_LOGGER.warning("*** / / / \ \ \ *** mise a jour attributes precedent %s " %( self._attributes ))
#on sauvegarde les elements pour les reprendre si errot
self.setLastAttributes()
self.setLastState()
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/testEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def testMulti():
testComplet( myDataEnedis )
print("***")
print( myDataEnedis.getLastMethodCallError())
print( myDataEnedis.getLastAnswer())
#print( myDataEnedis.getLastAnswer())

def testMono():
import configparser
Expand Down

0 comments on commit d90e234

Please sign in to comment.