-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix linky sensor login error #17110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix linky sensor login error #17110
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3fd0894
Fix linky sensor login error
164d82e
Make platform fail-safe
hobbe 00aabb5
Merge pull request #1 from hobbe/patch-1
Debaru ce363ee
Fix Hound CI error: line too long.
hobbe 36676e0
Merge pull request #2 from hobbe/patch-1
Debaru 0d2ca56
Merge remote-tracking branch 'upstream/dev' into dev
276c46b
Update pylinky library
7eddc42
Remove LinkyClient from update()
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,24 +37,27 @@ 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) | ||
| return | ||
| finally: | ||
| client.close_session() | ||
|
|
||
| devices = [LinkySensor('Linky', client)] | ||
| devices = [LinkySensor('Linky', username, password, timeout)] | ||
| add_entities(devices, True) | ||
|
|
||
|
|
||
| class LinkySensor(Entity): | ||
| """Representation of a sensor entity for Linky.""" | ||
|
|
||
| def __init__(self, name, client): | ||
| def __init__(self, name, username, password, timeout): | ||
| """Initialize the sensor.""" | ||
| self._name = name | ||
| self._client = client | ||
| self._username = username | ||
| self._password = password | ||
| self._timeout = timeout | ||
| self._state = None | ||
|
|
||
| @property | ||
|
|
@@ -75,17 +78,21 @@ def unit_of_measurement(self): | |
| @Throttle(SCAN_INTERVAL) | ||
| def update(self): | ||
| """Fetch new state data for the sensor.""" | ||
| from pylinky.client import PyLinkyError | ||
| from pylinky.client import LinkyClient, PyLinkyError | ||
|
|
||
| client = LinkyClient(self._username, self._password, None, self._timeout) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (81 > 79 characters) |
||
| try: | ||
| self._client.fetch_data() | ||
| client.fetch_data() | ||
| except PyLinkyError as exp: | ||
| _LOGGER.error(exp) | ||
| return | ||
| finally: | ||
| client.close_session() | ||
|
|
||
| _LOGGER.debug(json.dumps(self._client.get_data(), indent=2)) | ||
| _LOGGER.debug(json.dumps(client.get_data(), indent=2)) | ||
|
|
||
| if self._client.get_data(): | ||
| if client.get_data(): | ||
| # get the last past day data | ||
| self._state = self._client.get_data()['daily'][-2]['conso'] | ||
| self._state = client.get_data()['daily'][-2]['conso'] | ||
| else: | ||
| self._state = None | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'pylinky.client.LinkyClient' imported but unused