mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Adds SigFox sensor (#13731)
* Create sigfox.py * Create test_sigfox.py * Update .coveragerc * Fix lints * Fix logger message string * More lints * Address reviewer comments * edit exception handling * Update sigfox.py * Update sigfox.py * Update sigfox.py * Update sigfox.py
This commit is contained in:
68
tests/components/sensor/test_sigfox.py
Normal file
68
tests/components/sensor/test_sigfox.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Tests for the sigfox sensor."""
|
||||
import re
|
||||
import requests_mock
|
||||
import unittest
|
||||
|
||||
from homeassistant.components.sensor.sigfox import (
|
||||
API_URL, CONF_API_LOGIN, CONF_API_PASSWORD)
|
||||
from homeassistant.setup import setup_component
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
TEST_API_LOGIN = 'foo'
|
||||
TEST_API_PASSWORD = 'ebcd1234'
|
||||
|
||||
VALID_CONFIG = {
|
||||
'sensor': {
|
||||
'platform': 'sigfox',
|
||||
CONF_API_LOGIN: TEST_API_LOGIN,
|
||||
CONF_API_PASSWORD: TEST_API_PASSWORD}}
|
||||
|
||||
VALID_MESSAGE = """
|
||||
{"data":[{
|
||||
"time":1521879720,
|
||||
"data":"7061796c6f6164",
|
||||
"rinfos":[{"lat":"0.0","lng":"0.0"}],
|
||||
"snr":"50.0"}]}
|
||||
"""
|
||||
|
||||
|
||||
class TestSigfoxSensor(unittest.TestCase):
|
||||
"""Test the sigfox platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize values for this testcase class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_invalid_credentials(self):
|
||||
"""Test for a invalid credentials."""
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = re.compile(API_URL + 'devicetypes')
|
||||
mock_req.get(url, text='{}', status_code=401)
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, 'sensor', VALID_CONFIG))
|
||||
assert len(self.hass.states.entity_ids()) == 0
|
||||
|
||||
def test_valid_credentials(self):
|
||||
"""Test for a valid credentials."""
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url1 = re.compile(API_URL + 'devicetypes')
|
||||
mock_req.get(url1, text='{"data":[{"id":"fake_type"}]}',
|
||||
status_code=200)
|
||||
|
||||
url2 = re.compile(API_URL + 'devicetypes/fake_type/devices')
|
||||
mock_req.get(url2, text='{"data":[{"id":"fake_id"}]}')
|
||||
|
||||
url3 = re.compile(API_URL + 'devices/fake_id/messages*')
|
||||
mock_req.get(url3, text=VALID_MESSAGE)
|
||||
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, 'sensor', VALID_CONFIG))
|
||||
|
||||
assert len(self.hass.states.entity_ids()) == 1
|
||||
state = self.hass.states.get('sensor.sigfox_fake_id')
|
||||
assert state.state == 'payload'
|
||||
assert state.attributes.get('snr') == '50.0'
|
||||
Reference in New Issue
Block a user