mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Move imports to top for fido (#29557)
* Move imports to top for fido * Fix tests for fido by using patch
This commit is contained in:
parent
6de8072e8a
commit
d752fe3033
@ -7,21 +7,23 @@ https://www.fido.ca/pages/#/my-account/wireless
|
|||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.fido/
|
https://home-assistant.io/components/sensor.fido/
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from pyfido import FidoClient
|
||||||
|
from pyfido.client import PyFidoError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_USERNAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_MONITORED_VARIABLES,
|
CONF_MONITORED_VARIABLES,
|
||||||
|
CONF_NAME,
|
||||||
|
CONF_PASSWORD,
|
||||||
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -147,7 +149,6 @@ class FidoData:
|
|||||||
|
|
||||||
def __init__(self, username, password, httpsession):
|
def __init__(self, username, password, httpsession):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
from pyfido import FidoClient
|
|
||||||
|
|
||||||
self.client = FidoClient(username, password, REQUESTS_TIMEOUT, httpsession)
|
self.client = FidoClient(username, password, REQUESTS_TIMEOUT, httpsession)
|
||||||
self.data = {}
|
self.data = {}
|
||||||
@ -155,7 +156,6 @@ class FidoData:
|
|||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data from Fido."""
|
"""Get the latest data from Fido."""
|
||||||
from pyfido.client import PyFidoError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.client.fetch_data()
|
await self.client.fetch_data()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components.fido import sensor as fido
|
from homeassistant.components.fido import sensor as fido
|
||||||
@ -66,13 +66,9 @@ def fake_async_add_entities(component, update_before_add=False):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_fido_sensor(loop, hass):
|
def test_fido_sensor(loop, hass):
|
||||||
"""Test the Fido number sensor."""
|
"""Test the Fido number sensor."""
|
||||||
sys.modules["pyfido"] = MagicMock()
|
with patch(
|
||||||
sys.modules["pyfido.client"] = MagicMock()
|
"homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock
|
||||||
sys.modules["pyfido.client.PyFidoError"] = PyFidoErrorMock
|
), patch("homeassistant.components.fido.sensor.PyFidoError", new=PyFidoErrorMock):
|
||||||
import pyfido.client
|
|
||||||
|
|
||||||
pyfido.FidoClient = FidoClientMock
|
|
||||||
pyfido.client.PyFidoError = PyFidoErrorMock
|
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"platform": "fido",
|
"platform": "fido",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user