Fix linky sensor login error (#17110)

* Fix linky sensor login error

* Make platform fail-safe

Adding following enhancements:
* Make sure the platform loads correctly by making the first API request in setup_platform.
* Close the session after each API call.
* Use timeout parameter everywhere.

* Fix Hound CI error: line too long.

* Update pylinky library

* Remove LinkyClient from update()
This commit is contained in:
Julien Debaru 2018-10-20 15:30:10 +02:00 committed by Martin Hjelmare
parent 26b7c2de7e
commit e980d1b9fe
2 changed files with 4 additions and 3 deletions

View File

@ -16,7 +16,7 @@ from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['pylinky==0.1.6']
REQUIREMENTS = ['pylinky==0.1.8']
_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(minutes=10)
@ -37,11 +37,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
from pylinky.client import LinkyClient, PyLinkyError
client = LinkyClient(username, password, None, timeout)
try:
client.fetch_data()
except PyLinkyError as exp:
_LOGGER.error(exp)
client.close_session()
return
devices = [LinkySensor('Linky', client)]
@ -80,6 +80,7 @@ class LinkySensor(Entity):
self._client.fetch_data()
except PyLinkyError as exp:
_LOGGER.error(exp)
self._client.close_session()
return
_LOGGER.debug(json.dumps(self._client.get_data(), indent=2))

View File

@ -963,7 +963,7 @@ pylgnetcast-homeassistant==0.2.0.dev0
pylgtv==0.1.9
# homeassistant.components.sensor.linky
pylinky==0.1.6
pylinky==0.1.8
# homeassistant.components.litejet
pylitejet==0.1