mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix setup for tank_utility component (#29902)
This commit is contained in:
parent
c59bf0bff6
commit
9fbb6d981a
@ -4,7 +4,7 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import tank_utility
|
from tank_utility import auth, device as tank_monitor
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -47,7 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
devices = config.get(CONF_DEVICES)
|
devices = config.get(CONF_DEVICES)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = tank_utility.auth.get_token(email, password)
|
token = auth.get_token(email, password)
|
||||||
except requests.exceptions.HTTPError as http_error:
|
except requests.exceptions.HTTPError as http_error:
|
||||||
if (
|
if (
|
||||||
http_error.response.status_code
|
http_error.response.status_code
|
||||||
@ -111,7 +111,7 @@ class TankUtilitySensor(Entity):
|
|||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
try:
|
try:
|
||||||
data = tank_utility.device.get_device_data(self._token, self.device)
|
data = tank_monitor.get_device_data(self._token, self.device)
|
||||||
except requests.exceptions.HTTPError as http_error:
|
except requests.exceptions.HTTPError as http_error:
|
||||||
if (
|
if (
|
||||||
http_error.response.status_code
|
http_error.response.status_code
|
||||||
@ -120,10 +120,8 @@ class TankUtilitySensor(Entity):
|
|||||||
== requests.codes.bad_request # pylint: disable=no-member
|
== requests.codes.bad_request # pylint: disable=no-member
|
||||||
):
|
):
|
||||||
_LOGGER.info("Getting new token")
|
_LOGGER.info("Getting new token")
|
||||||
self._token = tank_utility.auth.get_token(
|
self._token = auth.get_token(self._email, self._password, force=True)
|
||||||
self._email, self._password, force=True
|
data = tank_monitor.get_device_data(self._token, self.device)
|
||||||
)
|
|
||||||
data = tank_utility.device.get_device_data(self._token, self.device)
|
|
||||||
else:
|
else:
|
||||||
raise http_error
|
raise http_error
|
||||||
data.update(data.pop("device", {}))
|
data.update(data.pop("device", {}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user