Skip to content

Commit

Permalink
Remove unnecessary default values from config schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 18, 2023
1 parent 6f81e99 commit 212a6b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 119 deletions.
32 changes: 14 additions & 18 deletions custom_components/yandex_smart_home/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import SERVICE_RELOAD, UnitOfPressure
from homeassistant.const import SERVICE_RELOAD
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entityfilter import BASE_FILTER_SCHEMA, FILTER_SCHEMA
Expand Down Expand Up @@ -105,16 +105,16 @@
vol.Optional(const.CONF_TURN_OFF): vol.Any(cv.SERVICE_SCHEMA, cv.boolean),
vol.Optional(const.CONF_DEVICE_CLASS): vol.In(const.DEVICE_CLASS_BUTTON),
vol.Optional(const.CONF_FEATURES): vol.All(cv.ensure_list, ycv.entity_features),
vol.Optional(const.CONF_ENTITY_PROPERTIES, default=[]): [ENTITY_PROPERTY_SCHEMA],
vol.Optional(const.CONF_ENTITY_PROPERTIES): [ENTITY_PROPERTY_SCHEMA],
vol.Optional(const.CONF_SUPPORT_SET_CHANNEL): cv.boolean,
vol.Optional(const.CONF_STATE_UNKNOWN): cv.boolean,
vol.Optional(const.CONF_COLOR_PROFILE): cv.string,
vol.Optional(const.CONF_ERROR_CODE_TEMPLATE): cv.template,
vol.Optional(const.CONF_ENTITY_RANGE, default={}): ENTITY_RANGE_SCHEMA,
vol.Optional(const.CONF_ENTITY_MODE_MAP, default={}): ENTITY_MODE_MAP_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_MODES, default={}): ENTITY_CUSTOM_MODE_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_TOGGLES, default={}): ENTITY_CUSTOM_TOGGLE_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_RANGES, default={}): ENTITY_CUSTOM_RANGE_SCHEMA,
vol.Optional(const.CONF_ENTITY_RANGE): ENTITY_RANGE_SCHEMA,
vol.Optional(const.CONF_ENTITY_MODE_MAP): ENTITY_MODE_MAP_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_MODES): ENTITY_CUSTOM_MODE_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_TOGGLES): ENTITY_CUSTOM_TOGGLE_SCHEMA,
vol.Optional(const.CONF_ENTITY_CUSTOM_RANGES): ENTITY_CUSTOM_RANGE_SCHEMA,
}
)
)
Expand All @@ -130,25 +130,21 @@

SETTINGS_SCHEMA = vol.Schema(
{
vol.Optional(const.CONF_PRESSURE_UNIT, default=UnitOfPressure.MMHG.value): vol.Schema(
vol.All(str, ycv.pressure_unit)
),
vol.Optional(const.CONF_BETA, default=False): cv.boolean,
vol.Optional(const.CONF_CLOUD_STREAM, default=False): cv.boolean,
vol.Optional(const.CONF_PRESSURE_UNIT): vol.Schema(vol.All(str, ycv.pressure_unit)),
vol.Optional(const.CONF_BETA): cv.boolean,
vol.Optional(const.CONF_CLOUD_STREAM): cv.boolean,
}
)


YANDEX_SMART_HOME_SCHEMA = vol.All(
vol.Schema(
{
vol.Optional(const.CONF_NOTIFIER, default=[]): vol.All(cv.ensure_list, [NOTIFIER_SCHEMA]),
vol.Optional(const.CONF_SETTINGS, default={}): vol.All(lambda value: value or {}, SETTINGS_SCHEMA),
vol.Optional(const.CONF_NOTIFIER): vol.All(cv.ensure_list, [NOTIFIER_SCHEMA]),
vol.Optional(const.CONF_SETTINGS): vol.All(lambda value: value or {}, SETTINGS_SCHEMA),
vol.Optional(const.CONF_FILTER): BASE_FILTER_SCHEMA,
vol.Optional(const.CONF_ENTITY_CONFIG, default={}): vol.All(
lambda value: value or {}, {cv.entity_id: ENTITY_SCHEMA}
),
vol.Optional(const.CONF_COLOR_PROFILE, default={}): vol.Schema(
vol.Optional(const.CONF_ENTITY_CONFIG): vol.All(lambda value: value or {}, {cv.entity_id: ENTITY_SCHEMA}),
vol.Optional(const.CONF_COLOR_PROFILE): vol.Schema(
{cv.string: {vol.All(ycv.color_name): vol.All(ycv.color_value)}}
),
},
Expand Down
29 changes: 0 additions & 29 deletions tests/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -159,44 +159,20 @@
}),
}),
'yaml_config': dict({
'color_profile': dict({
}),
'entity_config': dict({
'light.kitchen': dict({
'custom_modes': dict({
}),
'custom_ranges': dict({
}),
'custom_toggles': dict({
}),
'modes': dict({
}),
'properties': list([
dict({
'entity': 'sensor.invalid',
'type': 'temperature',
}),
]),
'range': dict({
}),
}),
'switch.with_template': dict({
'custom_modes': dict({
}),
'custom_ranges': dict({
}),
'custom_toggles': dict({
}),
'error_code_template': dict({
'__type': "<class 'homeassistant.helpers.template.Template'>",
'repr': 'Template<template=({{ "a" + "b" }}) renders=0>',
}),
'modes': dict({
}),
'properties': list([
]),
'range': dict({
}),
}),
}),
'filter': dict({
Expand All @@ -217,11 +193,6 @@
]),
}),
'notifier': '**REDACTED**',
'settings': dict({
'beta': False,
'cloud_stream': False,
'pressure_unit': 'mmHg',
}),
}),
}),
})
Expand Down
74 changes: 2 additions & 72 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def test_valid_config(hass):
"user_id": "e8701ad48ba05a91604e480dd60899a3",
}
]
assert config[DOMAIN]["settings"] == {"pressure_unit": "mmHg", "beta": True, "cloud_stream": False}
assert config[DOMAIN]["settings"] == {"pressure_unit": "mmHg", "beta": True}
assert config[DOMAIN]["color_profile"] == {"test": {"red": 16711680, "green": 65280, "warm_white": 3000}}
assert config[DOMAIN]["filter"] == {
"include_domains": ["switch", "light", "climate"],
Expand All @@ -51,22 +51,11 @@ async def test_valid_config(hass):

assert entity_config["switch.kitchen"] == {
"name": "Выключатель",
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}
assert entity_config["light.living_room"] == {
"name": "Люстра",
"modes": {"scene": {"sunrise": ["Wake up"], "alarm": ["Blink"]}},
"color_profile": "natural",
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"custom_modes": {},
}
assert entity_config["media_player.tv_lg"] == {
"custom_ranges": {
Expand All @@ -85,11 +74,6 @@ async def test_valid_config(hass):
"decrease_value": {"service": "script.decrease_volume"},
},
},
"custom_toggles": {},
"properties": [],
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["fan.xiaomi_miio_device"] == {
Expand All @@ -101,11 +85,6 @@ async def test_valid_config(hass):
{"type": "humidity", "attribute": "humidity"},
{"type": "water_level", "attribute": "depth"},
],
"custom_toggles": {},
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["climate.tion_breezer"] == {
Expand All @@ -121,32 +100,16 @@ async def test_valid_config(hass):
"max": ["6", "6.0"],
}
},
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"custom_modes": {},
}

assert entity_config["media_player.receiver"] == {
"type": "devices.types.media_device.receiver",
"range": {"max": 95.0, "min": 20.0, "precision": 2.0},
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["media_player.cast"] == {
"support_set_channel": False,
"features": ["volume_mute", "volume_set", "next_previous_track"],
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["climate.ac_living_room"] == {
Expand All @@ -165,11 +128,6 @@ async def test_valid_config(hass):
"turn_off": {"service": "input_boolean.turn_off", "entity_id": ["input_boolean.ac_lighting"]},
},
},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert isinstance(entity_config["switch.r4s1_kettle_boil"]["error_code_template"], Template)
Expand All @@ -191,53 +149,25 @@ async def test_valid_config(hass):
"properties": [
{"type": "temperature", "entity": "climate.r4s1_kettle_temp", "attribute": "current_temperature"}
],
"custom_toggles": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["cover.ir_cover"] == {
"name": "Глупые шторы",
"state_unknown": True,
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["input_text.button"] == {
"name": "Кнопка на автоматизации",
"device_class": "button",
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["lock.front_door"] == {
"type": "devices.types.openable",
"turn_on": False,
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}

assert entity_config["climate.ac"] == {
"turn_on": {"data": {"mode": "cool"}, "entity_id": ["climate.ac"], "service": "climate.turn_on"},
"custom_toggles": {},
"properties": [],
"custom_ranges": {},
"range": {},
"modes": {},
"custom_modes": {},
}


Expand All @@ -261,7 +191,7 @@ async def test_reload_no_config_entry(hass, hass_admin_user):
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})

component: YandexSmartHome = hass.data[DOMAIN]
assert component._yaml_config["entity_config"] == {}
assert component._yaml_config.get("entity_config") is None

files = {
YAML_CONFIG_FILE: """
Expand Down

0 comments on commit 212a6b8

Please sign in to comment.