Skip to content

Commit

Permalink
Preserve customize glob order. (#6963)
Browse files Browse the repository at this point in the history
* Preserve customize glob order.

* add tests
  • Loading branch information
andrey-git authored and balloob committed Apr 7, 2017
1 parent 3e66df5 commit f96e06a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
vol.Optional(CONF_DEVICE_CONFIG, default={}):
vol.Schema({cv.entity_id: DEVICE_CONFIG_SCHEMA_ENTRY}),
vol.Optional(CONF_DEVICE_CONFIG_GLOB, default={}):
vol.Schema({cv.string: DEVICE_CONFIG_SCHEMA_ENTRY}),
cv.ordered_dict(DEVICE_CONFIG_SCHEMA_ENTRY, cv.string),
vol.Optional(CONF_DEVICE_CONFIG_DOMAIN, default={}):
vol.Schema({cv.string: DEVICE_CONFIG_SCHEMA_ENTRY}),
vol.Optional(CONF_DEBUG, default=DEFAULT_DEBUG): cv.boolean,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
vol.Optional(CONF_CUSTOMIZE_DOMAIN, default={}):
vol.Schema({cv.string: dict}),
vol.Optional(CONF_CUSTOMIZE_GLOB, default={}):
vol.Schema({cv.string: dict}),
cv.ordered_dict(OrderedDict, cv.string),
})

CORE_CONFIG_SCHEMA = CUSTOMIZE_CONFIG_SCHEMA.extend({
Expand Down
15 changes: 15 additions & 0 deletions tests/components/zwave/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Tests for the Z-Wave init."""
import asyncio
import unittest
from collections import OrderedDict

from homeassistant.bootstrap import async_setup_component
from homeassistant.components.zwave import (
CONFIG_SCHEMA, CONF_DEVICE_CONFIG_GLOB)


@asyncio.coroutine
Expand Down Expand Up @@ -34,3 +38,14 @@ def test_invalid_device_config(hass, mock_openzwave):
}})

assert not result


class TestZwave(unittest.TestCase):
"""Test zwave init."""

def test_device_config_glob_is_ordered(self):
"""Test that device_config_glob preserves order."""
conf = CONFIG_SCHEMA(
{'zwave': {CONF_DEVICE_CONFIG_GLOB: OrderedDict()}})
self.assertIsInstance(
conf['zwave'][CONF_DEVICE_CONFIG_GLOB], OrderedDict)
7 changes: 7 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import unittest
import unittest.mock as mock
from collections import OrderedDict

import pytest
from voluptuous import MultipleInvalid
Expand Down Expand Up @@ -205,6 +206,12 @@ def test_core_config_schema(self):
},
})

def test_customize_glob_is_ordered(self):
"""Test that customize_glob preserves order."""
conf = config_util.CORE_CONFIG_SCHEMA(
{'customize_glob': OrderedDict()})
self.assertIsInstance(conf['customize_glob'], OrderedDict)

def _compute_state(self, config):
run_coroutine_threadsafe(
config_util.async_process_ha_core_config(self.hass, config),
Expand Down

0 comments on commit f96e06a

Please sign in to comment.