Storage entity registry (#16018)
* Split out storage delayed write * Update code using delayed save * Fix tests * Fix typing test * Add callback decorator * Migrate entity registry to storage helper * Make double loading protection easier * Lint * Fix tests * Ordered Dict
This commit is contained in:
parent
ef193b0f64
commit
8ec550d6e0
7 changed files with 167 additions and 149 deletions
|
@ -5,13 +5,14 @@ from datetime import timedelta, datetime
|
|||
from unittest.mock import patch
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import mock_mqtt_component, fire_mqtt_message, \
|
||||
assert_setup_component
|
||||
assert_setup_component, async_fire_mqtt_message, \
|
||||
async_mock_mqtt_component
|
||||
from tests.common import get_test_home_assistant, mock_component
|
||||
|
||||
|
||||
|
@ -331,27 +332,6 @@ class TestSensorMQTT(unittest.TestCase):
|
|||
state.attributes.get('val'))
|
||||
self.assertEqual('100', state.state)
|
||||
|
||||
def test_unique_id(self):
|
||||
"""Test unique id option only creates one sensor per unique_id."""
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
sensor.DOMAIN: [{
|
||||
'platform': 'mqtt',
|
||||
'name': 'Test 1',
|
||||
'state_topic': 'test-topic',
|
||||
'unique_id': 'TOTALLY_UNIQUE'
|
||||
}, {
|
||||
'platform': 'mqtt',
|
||||
'name': 'Test 2',
|
||||
'state_topic': 'test-topic',
|
||||
'unique_id': 'TOTALLY_UNIQUE'
|
||||
}]
|
||||
})
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', 'payload')
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(self.hass.states.all()) == 1
|
||||
|
||||
def test_invalid_device_class(self):
|
||||
"""Test device_class option with invalid value."""
|
||||
with assert_setup_component(0):
|
||||
|
@ -384,3 +364,26 @@ class TestSensorMQTT(unittest.TestCase):
|
|||
assert state.attributes['device_class'] == 'temperature'
|
||||
state = self.hass.states.get('sensor.test_2')
|
||||
assert 'device_class' not in state.attributes
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
"""Test unique id option only creates one sensor per unique_id."""
|
||||
await async_mock_mqtt_component(hass)
|
||||
assert await async_setup_component(hass, sensor.DOMAIN, {
|
||||
sensor.DOMAIN: [{
|
||||
'platform': 'mqtt',
|
||||
'name': 'Test 1',
|
||||
'state_topic': 'test-topic',
|
||||
'unique_id': 'TOTALLY_UNIQUE'
|
||||
}, {
|
||||
'platform': 'mqtt',
|
||||
'name': 'Test 2',
|
||||
'state_topic': 'test-topic',
|
||||
'unique_id': 'TOTALLY_UNIQUE'
|
||||
}]
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue