* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
"""The tests for Efergy sensor platform."""
|
|
import unittest
|
|
|
|
import requests_mock
|
|
|
|
from homeassistant.setup import setup_component
|
|
|
|
from tests.common import load_fixture, get_test_home_assistant
|
|
|
|
token = '9p6QGJ7dpZfO3fqPTBk1fyEmjV1cGoLT'
|
|
multi_sensor_token = '9r6QGF7dpZfO3fqPTBl1fyRmjV1cGoLT'
|
|
|
|
ONE_SENSOR_CONFIG = {
|
|
'platform': 'efergy',
|
|
'app_token': token,
|
|
'utc_offset': '300',
|
|
'monitored_variables': [
|
|
{'type': 'amount', 'period': 'day'},
|
|
{'type': 'instant_readings'},
|
|
{'type': 'budget'},
|
|
{'type': 'cost', 'period': 'day', 'currency': '$'},
|
|
{'type': 'current_values'},
|
|
]
|
|
}
|
|
|
|
MULTI_SENSOR_CONFIG = {
|
|
'platform': 'efergy',
|
|
'app_token': multi_sensor_token,
|
|
'utc_offset': '300',
|
|
'monitored_variables': [{'type': 'current_values'}],
|
|
}
|
|
|
|
|
|
def mock_responses(mock):
|
|
"""Mock responses for Efergy."""
|
|
base_url = 'https://engage.efergy.com/mobile_proxy/'
|
|
mock.get(
|
|
'{}getInstant?token={}'.format(base_url, token),
|
|
text=load_fixture('efergy_instant.json'))
|
|
mock.get(
|
|
'{}getEnergy?token={}&offset=300&period=day'.format(base_url, token),
|
|
text=load_fixture('efergy_energy.json'))
|
|
mock.get(
|
|
'{}getBudget?token={}'.format(base_url, token),
|
|
text=load_fixture('efergy_budget.json'))
|
|
mock.get(
|
|
'{}getCost?token={}&offset=300&period=day'.format(base_url, token),
|
|
text=load_fixture('efergy_cost.json'))
|
|
mock.get(
|
|
'{}getCurrentValuesSummary?token={}'.format(base_url, token),
|
|
text=load_fixture('efergy_current_values_single.json'))
|
|
mock.get(
|
|
'{}getCurrentValuesSummary?token={}'.format(
|
|
base_url, multi_sensor_token),
|
|
text=load_fixture('efergy_current_values_multi.json'))
|
|
|
|
|
|
class TestEfergySensor(unittest.TestCase):
|
|
"""Tests the Efergy Sensor platform."""
|
|
|
|
DEVICES = []
|
|
|
|
@requests_mock.Mocker()
|
|
def add_entities(self, devices, mock):
|
|
"""Mock add devices."""
|
|
mock_responses(mock)
|
|
for device in devices:
|
|
device.update()
|
|
self.DEVICES.append(device)
|
|
|
|
def setUp(self):
|
|
"""Initialize values for this test case class."""
|
|
self.hass = get_test_home_assistant()
|
|
self.config = ONE_SENSOR_CONFIG
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
"""Stop everything that was started."""
|
|
self.hass.stop()
|
|
|
|
@requests_mock.Mocker()
|
|
def test_single_sensor_readings(self, mock):
|
|
"""Test for successfully setting up the Efergy platform."""
|
|
mock_responses(mock)
|
|
assert setup_component(self.hass, 'sensor', {
|
|
'sensor': ONE_SENSOR_CONFIG,
|
|
})
|
|
|
|
assert '38.21' == self.hass.states.get('sensor.energy_consumed').state
|
|
assert '1580' == self.hass.states.get('sensor.energy_usage').state
|
|
assert 'ok' == self.hass.states.get('sensor.energy_budget').state
|
|
assert '5.27' == self.hass.states.get('sensor.energy_cost').state
|
|
assert '1628' == self.hass.states.get('sensor.efergy_728386').state
|
|
|
|
@requests_mock.Mocker()
|
|
def test_multi_sensor_readings(self, mock):
|
|
"""Test for multiple sensors in one household."""
|
|
mock_responses(mock)
|
|
assert setup_component(self.hass, 'sensor', {
|
|
'sensor': MULTI_SENSOR_CONFIG,
|
|
})
|
|
|
|
assert '218' == self.hass.states.get('sensor.efergy_728386').state
|
|
assert '1808' == self.hass.states.get('sensor.efergy_0').state
|
|
assert '312' == self.hass.states.get('sensor.efergy_728387').state
|