Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
3ddcffb7
Unverified
Commit
3ddcffb7
authored
8 months ago
by
Mr. Bubbles
Committed by
GitHub
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix reauth error and exception in ista EcoTrend integration (#121482)
parent
8cb7e978
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/ista_ecotrend/coordinator.py
+24
-26
24 additions, 26 deletions
homeassistant/components/ista_ecotrend/coordinator.py
with
24 additions
and
26 deletions
homeassistant/components/ista_ecotrend/coordinator.py
+
24
−
26
View file @
3ddcffb7
...
...
@@ -8,6 +8,7 @@ from typing import Any
from
pyecotrend_ista
import
KeycloakError
,
LoginError
,
PyEcotrendIsta
,
ServerError
from
homeassistant.config_entries
import
ConfigEntry
from
homeassistant.const
import
CONF_EMAIL
from
homeassistant.core
import
HomeAssistant
from
homeassistant.exceptions
import
ConfigEntryAuthFailed
...
...
@@ -21,6 +22,8 @@ _LOGGER = logging.getLogger(__name__)
class
IstaCoordinator
(
DataUpdateCoordinator
[
dict
[
str
,
Any
]]):
"""
Ista EcoTrend data update coordinator.
"""
config_entry
:
ConfigEntry
def
__init__
(
self
,
hass
:
HomeAssistant
,
ista
:
PyEcotrendIsta
)
->
None
:
"""
Initialize ista EcoTrend data update coordinator.
"""
super
().
__init__
(
...
...
@@ -35,11 +38,14 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
async
def
_async_update_data
(
self
):
"""
Fetch ista EcoTrend data.
"""
if
not
self
.
details
:
self
.
details
=
await
self
.
async_get_details
()
try
:
await
self
.
hass
.
async_add_executor_job
(
self
.
ista
.
login
)
if
not
self
.
details
:
self
.
details
=
await
self
.
async_get_details
()
return
await
self
.
hass
.
async_add_executor_job
(
self
.
get_consumption_data
)
except
ServerError
as
e
:
raise
UpdateFailed
(
"
Unable to connect and retrieve data from ista EcoTrend, try again later
"
...
...
@@ -48,7 +54,9 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
raise
ConfigEntryAuthFailed
(
translation_domain
=
DOMAIN
,
translation_key
=
"
authentication_exception
"
,
translation_placeholders
=
{
CONF_EMAIL
:
self
.
ista
.
_email
},
# noqa: SLF001
translation_placeholders
=
{
CONF_EMAIL
:
self
.
config_entry
.
data
[
CONF_EMAIL
]
},
)
from
e
def
get_consumption_data
(
self
)
->
dict
[
str
,
Any
]:
...
...
@@ -61,26 +69,16 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
async
def
async_get_details
(
self
)
->
dict
[
str
,
Any
]:
"""
Retrieve details of consumption units.
"""
try
:
result
=
await
self
.
hass
.
async_add_executor_job
(
self
.
ista
.
get_consumption_unit_details
result
=
await
self
.
hass
.
async_add_executor_job
(
self
.
ista
.
get_consumption_unit_details
)
return
{
consumption_unit
:
next
(
details
for
details
in
result
[
"
consumptionUnits
"
]
if
details
[
"
id
"
]
==
consumption_unit
)
except
ServerError
as
e
:
raise
UpdateFailed
(
"
Unable to connect and retrieve data from ista EcoTrend, try again later
"
)
from
e
except
(
LoginError
,
KeycloakError
)
as
e
:
raise
ConfigEntryAuthFailed
(
translation_domain
=
DOMAIN
,
translation_key
=
"
authentication_exception
"
,
translation_placeholders
=
{
CONF_EMAIL
:
self
.
ista
.
_email
},
# noqa: SLF001
)
from
e
else
:
return
{
consumption_unit
:
next
(
details
for
details
in
result
[
"
consumptionUnits
"
]
if
details
[
"
id
"
]
==
consumption_unit
)
for
consumption_unit
in
self
.
ista
.
get_uuids
()
}
for
consumption_unit
in
self
.
ista
.
get_uuids
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment