Skip to content

Commit

Permalink
update schemas to use inclusive and exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart99 committed Dec 17, 2020
1 parent 56b88cc commit 56bd1e3
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 101 deletions.
21 changes: 14 additions & 7 deletions docs/light.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,25 @@ groups:
# Light with RGBW color
Kitchen.Light_rgbw:
{
white: {group_address_switch: "1/6/4", group_address_switch_state: "1/6/5", group_address_brightness: "1/6/6", group_address_brightness_state: "1/6/7"},
red: {group_address_switch: "1/6/14", group_address_switch_state: "1/6/15", group_address_brightness: "1/6/16", group_address_brightness_state: "1/6/17"},
green: {group_address_switch: "1/6/24", group_address_switch_state: "1/6/25", group_address_brightness: "1/6/26", group_address_brightness_state: "1/6/27"},
blue: {group_address_switch: "1/6/34", group_address_switch_state: "1/6/35", group_address_brightness: "1/6/36", group_address_brightness_state: "1/6/37"}
individual_colors:
{
white: {group_address_switch: "1/6/4", group_address_switch_state: "1/6/5", group_address_brightness: "1/6/6", group_address_brightness_state: "1/6/7"},
red: {group_address_switch: "1/6/14", group_address_switch_state: "1/6/15", group_address_brightness: "1/6/16", group_address_brightness_state: "1/6/17"},
green: {group_address_switch: "1/6/24", group_address_switch_state: "1/6/25", group_address_brightness: "1/6/26", group_address_brightness_state: "1/6/27"},
blue: {group_address_switch: "1/6/34", group_address_switch_state: "1/6/35", group_address_brightness: "1/6/36", group_address_brightness_state: "1/6/37"}
}
}

# Light with RGB color and no white
Kitchen.Light_rgb:
{
red: {group_address_switch: "1/6/14", group_address_switch_state: "1/6/15", group_address_brightness: "1/6/16", group_address_brightness_state: "1/6/17"},
green: {group_address_switch: "1/6/24", group_address_switch_state: "1/6/25", group_address_brightness: "1/6/26", group_address_brightness_state: "1/6/27"},
blue: {group_address_switch: "1/6/34", group_address_switch_state: "1/6/35", group_address_brightness: "1/6/36", group_address_brightness_state: "1/6/37"}
individual_colors:
{
red: {group_address_switch: "1/6/14", group_address_switch_state: "1/6/15", group_address_brightness: "1/6/16", group_address_brightness_state: "1/6/17"},
green: {group_address_switch: "1/6/24", group_address_switch_state: "1/6/25", group_address_brightness: "1/6/26", group_address_brightness_state: "1/6/27"},
blue: {group_address_switch: "1/6/34", group_address_switch_state: "1/6/35", group_address_brightness: "1/6/36", group_address_brightness_state: "1/6/37"}
}
r
}
```

12 changes: 6 additions & 6 deletions home-assistant-plugin/custom_components/xknx/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def _create_light_color(
color: str, config: ConfigType
) -> Tuple[Optional[str], Optional[str], Optional[str], Optional[str]]:
"""Load color configuration from configuration structure."""
if color in config:
sub_config = config[color]
if "individual_colors" in config and color in config["individual_colors"]:
sub_config = config["individual_colors"][color]
group_address_switch = sub_config.get(CONF_ADDRESS)
group_address_switch_state = sub_config.get(LightSchema.CONF_STATE_ADDRESS)
group_address_brightness = sub_config.get(LightSchema.CONF_BRIGHTNESS_ADDRESS)
Expand Down Expand Up @@ -132,25 +132,25 @@ def _create_light(knx_module: XKNX, config: ConfigType) -> XknxLight:
red_switch_state,
red_brightness,
red_brightness_state,
) = _create_light_color(LightSchema.RED, config)
) = _create_light_color(LightSchema.CONF_RED, config)
(
green_switch,
green_switch_state,
green_brightness,
green_brightness_state,
) = _create_light_color(LightSchema.GREEN, config)
) = _create_light_color(LightSchema.CONF_GREEN, config)
(
blue_switch,
blue_switch_state,
blue_brightness,
blue_brightness_state,
) = _create_light_color(LightSchema.BLUE, config)
) = _create_light_color(LightSchema.CONF_BLUE, config)
(
white_switch,
white_switch_state,
white_brightness,
white_brightness_state,
) = _create_light_color(LightSchema.WHITE, config)
) = _create_light_color(LightSchema.CONF_WHITE, config)

return XknxLight(
knx_module,
Expand Down
25 changes: 14 additions & 11 deletions home-assistant-plugin/custom_components/xknx/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ class LightSchema:
DEFAULT_MIN_KELVIN = 2700 # 370 mireds
DEFAULT_MAX_KELVIN = 6000 # 166 mireds

RED = "red"
GREEN = "green"
BLUE = "blue"
WHITE = "white"
CONF_INDIVIDUAL_COLORS = "individual_colors"
CONF_RED = "red"
CONF_GREEN = "green"
CONF_BLUE = "blue"
CONF_WHITE = "white"

COLOR_SCHEMA = vol.Schema(
{
vol.Optional(CONF_ADDRESS): cv.string,
vol.Optional(CONF_STATE_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_ADDRESS): cv.string,
vol.Required(CONF_BRIGHTNESS_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_STATE_ADDRESS): cv.string,
}
)
Expand All @@ -160,18 +161,20 @@ class LightSchema:
vol.Optional(CONF_STATE_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_STATE_ADDRESS): cv.string,
vol.Optional(RED): COLOR_SCHEMA,
vol.Optional(GREEN): COLOR_SCHEMA,
vol.Optional(BLUE): COLOR_SCHEMA,
vol.Optional(WHITE): COLOR_SCHEMA,
vol.Optional(CONF_COLOR_ADDRESS): cv.string,
vol.Exclusive(CONF_INDIVIDUAL_COLORS, "color"): {
vol.Inclusive(CONF_RED, "colors"): COLOR_SCHEMA,
vol.Inclusive(CONF_GREEN, "colors"): COLOR_SCHEMA,
vol.Inclusive(CONF_BLUE, "colors"): COLOR_SCHEMA,
vol.Optional(CONF_WHITE): COLOR_SCHEMA,
},
vol.Exclusive(CONF_COLOR_ADDRESS, "color"): cv.string,
vol.Optional(CONF_COLOR_STATE_ADDRESS): cv.string,
vol.Optional(CONF_COLOR_TEMP_ADDRESS): cv.string,
vol.Optional(CONF_COLOR_TEMP_STATE_ADDRESS): cv.string,
vol.Optional(
CONF_COLOR_TEMP_MODE, default=DEFAULT_COLOR_TEMP_MODE
): cv.enum(ColorTempModes),
vol.Optional(CONF_RGBW_ADDRESS): cv.string,
vol.Exclusive(CONF_RGBW_ADDRESS, "color"): cv.string,
vol.Optional(CONF_RGBW_STATE_ADDRESS): cv.string,
vol.Optional(CONF_MIN_KELVIN, default=DEFAULT_MIN_KELVIN): vol.All(
vol.Coerce(int), vol.Range(min=1)
Expand Down
25 changes: 25 additions & 0 deletions test/config_tests/resources/light/invalid_3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "two or more values in the same group of exclusion 'color' @ .*"
friendly_name: "Office"
switch:
address: "2/1/5"
state_address: "2/4/5"
state_update: "expire 60"
passive_state_addresses: ["8/8/8"]
brightness:
address: "2/5/5"
state_address: "2/5/6"
state_update: "expire 60"
passive_state_addresses: ["8/8/8"]
rgbw:
address: "2/4/5"
state_address: "2/4/6"
color:
address: "2/4/5"
state_address: "2/4/6"
color_temperature:
address: "2/5/7"
state_address: "2/5/8"
state_update: "expire 60"
mode: absolute
min_kelvin: 2550
max_kelvin: 6200
10 changes: 10 additions & 0 deletions test/config_tests/resources/light/valid_5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "office"
friendly_name: "Office"
switch:
address: "2/1/5"
state_address: "2/4/5"
state_update: "expire 60"
passive_state_addresses: ["8/8/8"]
color:
address: "2/4/5"
state_address: "2/4/6"
50 changes: 22 additions & 28 deletions test/config_tests/resources/light/valid_rgb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@ friendly_name: "Office"
# dummy for now
switch:
address: "2/1/5"
white:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
red:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
green:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
blue:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
individual_colors:
red:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
green:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
blue:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
34 changes: 34 additions & 0 deletions test/config_tests/resources/light/valid_rgbw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "office"
friendly_name: "Office"
# dummy for now
switch:
address: "2/1/5"
individual_colors:
white:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
red:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
green:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
blue:
switch:
address: "2/1/5"
state_address: "2/4/5"
brightness:
address: "2/5/7"
state_address: "2/5/8"
22 changes: 22 additions & 0 deletions test/config_tests/resources/light/valid_rgbw_no_switch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "office"
friendly_name: "Office"
# dummy for now
switch:
address: "2/1/5"
individual_colors:
white:
brightness:
address: "2/5/7"
state_address: "2/5/8"
red:
brightness:
address: "2/5/7"
state_address: "2/5/8"
green:
brightness:
address: "2/5/7"
state_address: "2/5/8"
blue:
brightness:
address: "2/5/7"
state_address: "2/5/8"
55 changes: 29 additions & 26 deletions xknx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,36 @@ groups:
# Light with color
Diningroom.Light_rgb:
{
white:
individual_colors:
{
group_address_switch: "1/6/4",
group_address_switch_state: "1/6/5",
group_address_brightness: "1/6/6",
group_address_brightness_state: "1/6/7",
},
red:
{
group_address_switch: "1/6/14",
group_address_switch_state: "1/6/15",
group_address_brightness: "1/6/16",
group_address_brightness_state: "1/6/17",
},
green:
{
group_address_switch: "1/6/24",
group_address_switch_state: "1/6/25",
group_address_brightness: "1/6/26",
group_address_brightness_state: "1/6/27",
},
blue:
{
group_address_switch: "1/6/34",
group_address_switch_state: "1/6/35",
group_address_brightness: "1/6/36",
group_address_brightness_state: "1/6/37",
white:
{
group_address_switch: "1/6/4",
group_address_switch_state: "1/6/5",
group_address_brightness: "1/6/6",
group_address_brightness_state: "1/6/7",
},
red:
{
group_address_switch: "1/6/14",
group_address_switch_state: "1/6/15",
group_address_brightness: "1/6/16",
group_address_brightness_state: "1/6/17",
},
green:
{
group_address_switch: "1/6/24",
group_address_switch_state: "1/6/25",
group_address_brightness: "1/6/26",
group_address_brightness_state: "1/6/27",
},
blue:
{
group_address_switch: "1/6/34",
group_address_switch_state: "1/6/35",
group_address_brightness: "1/6/36",
group_address_brightness_state: "1/6/37",
}
}
}
# Light with color temperature
Expand Down
23 changes: 12 additions & 11 deletions xknx/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class LightSchema:
CONF_RGBW = "rgbw"
CONF_COLOR_TEMPERATURE = "color_temperature"
CONF_COLOR = "color"
CONF_INDIVIDUAL_COLORS = "individual_colors"

CONF_COLOR_TEMP_MODE = "mode"
CONF_MIN_KELVIN = "min_kelvin"
Expand All @@ -163,10 +164,8 @@ class LightSchema:

COLOR_SCHEMA = vol.Schema(
{
vol.Optional(CONF_SWITCH): RemoteValueSchema.SCHEMA.extend(
{vol.Required(CONF_ADDRESS): ensure_group_address}
),
vol.Optional(CONF_BRIGHTNESS): RemoteValueSchema.SCHEMA.extend(
vol.Optional(CONF_SWITCH): RemoteValueSchema.SCHEMA,
vol.Required(CONF_BRIGHTNESS): RemoteValueSchema.SCHEMA.extend(
{vol.Required(CONF_ADDRESS): ensure_group_address}
),
}
Expand All @@ -180,12 +179,18 @@ class LightSchema:
vol.Optional(CONF_BRIGHTNESS): RemoteValueSchema.SCHEMA.extend(
{vol.Required(CONF_ADDRESS): ensure_group_address}
),
vol.Optional(CONF_RGBW): RemoteValueSchema.SCHEMA.extend(
vol.Exclusive(CONF_RGBW, "color"): RemoteValueSchema.SCHEMA.extend(
{vol.Required(CONF_ADDRESS): ensure_group_address}
),
vol.Optional(CONF_COLOR): RemoteValueSchema.SCHEMA.extend(
vol.Exclusive(CONF_COLOR, "color"): RemoteValueSchema.SCHEMA.extend(
{vol.Required(CONF_ADDRESS): ensure_group_address}
),
vol.Exclusive(CONF_INDIVIDUAL_COLORS, "color"): {
vol.Inclusive(CONF_RED, "colors"): COLOR_SCHEMA,
vol.Inclusive(CONF_GREEN, "colors"): COLOR_SCHEMA,
vol.Inclusive(CONF_BLUE, "colors"): COLOR_SCHEMA,
vol.Optional(CONF_WHITE): COLOR_SCHEMA,
},
vol.Optional(CONF_COLOR_TEMPERATURE): RemoteValueSchema.SCHEMA.extend(
{
vol.Required(CONF_ADDRESS): ensure_group_address,
Expand All @@ -200,11 +205,7 @@ class LightSchema:
),
}
),
vol.Optional(CONF_RED): COLOR_SCHEMA,
vol.Optional(CONF_GREEN): COLOR_SCHEMA,
vol.Optional(CONF_BLUE): COLOR_SCHEMA,
vol.Optional(CONF_WHITE): COLOR_SCHEMA,
}
},
)


Expand Down

0 comments on commit 56bd1e3

Please sign in to comment.