8000 Make default dim level configurable in Lutron by cameronr · Pull Request #137127 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make default dim level configurable in Lutron #137127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions homeassistant/components/lutron/config_flow.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@
from pylutron import Lutron
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.helpers.selector import (
NumberSelector,
NumberSelectorConfig,
NumberSelectorMode,
)

from .const import DOMAIN
from .const import CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL, DOMAIN

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,3 +79,36 @@
),
errors=errors,
)

@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
) -> OptionsFlowHandler:
"""Get the options flow for this handler."""
return OptionsFlowHandler()

Check warning on line 89 in homeassistant/components/lutron/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/config_flow.py#L89

Added line #L89 was not covered by tests
Copy link
Member
@MartinHjelmare MartinHjelmare Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are missing. The CI checks for required coverage failed.

Copy link
Contributor Author
@cameronr cameronr Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for the OptionsFlowHandler. Should I open another PR to submit it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. Thanks!



class OptionsFlowHandler(OptionsFlow):
"""Handle option flow for lutron."""

async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle options flow."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

Check warning on line 100 in homeassistant/components/lutron/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/config_flow.py#L99-L100

Added lines #L99 - L100 were not covered by tests

data_schema = vol.Schema(

Check warning on line 102 in homeassistant/components/lutron/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/config_flow.py#L102

Added line #L102 was not covered by tests
{
vol.Required(
CONF_DEFAULT_DIMMER_LEVEL,
default=self.config_entry.options.get(
CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL
),
): NumberSelector(
NumberSelectorConfig(min=1, max=255, mode=NumberSelectorMode.SLIDER)
)
}
)
return self.async_show_form(step_id="init", data_schema=data_schema)

Check warning on line 114 in homeassistant/components/lutron/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/config_flow.py#L114

Added line #L114 was not covered by tests
4 changes: 4 additions & 0 deletions homeassistant/components/lutron/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Lutron constants."""

DOMAIN = "lutron"

CONF_DEFAULT_DIMMER_LEVEL = "default_dimmer_level"

DEFAULT_DIMMER_LEVEL = 255 / 2
20 changes: 17 additions & 3 deletions homeassistant/components/lutron/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Mapping
from typing import Any

from pylutron import Output
from pylutron import Lutron, LutronEntity, Output

Check warning on line 8 in homeassistant/components/lutron/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/light.py#L8

Added line #L8 was not covered by tests

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
Expand All @@ -20,6 +20,7 @@
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from . import DOMAIN, LutronData
from .const import CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL

Check warning on line 23 in homeassistant/components/lutron/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/light.py#L23

Added line #L23 was not covered by tests
from .entity import LutronDevice


Expand All @@ -37,7 +38,7 @@

async_add_entities(
(
LutronLight(area_name, device, entry_data.client)
LutronLight(area_name, device, entry_data.client, config_entry)
for area_name, device in entry_data.lights
),
True,
Expand All @@ -64,6 +65,17 @@
_prev_brightness: int | None = None
_attr_name = None

def __init__(

Check warning on line 68 in homeassistant/components/lutron/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/light.py#L68

Added line #L68 was not covered by tests
self,
area_name: str,
lutron_device: LutronEntity,
controller: Lutron,
config_entry: ConfigEntry,
) -> None:
"""Initialize the device."""
super().__init__(area_name, lutron_device, controller)
self._config_entry = config_entry

Check warning on line 77 in homeassistant/components/lutron/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/light.py#L76-L77

Added lines #L76 - L77 were not covered by tests

def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if flash := kwargs.get(ATTR_FLASH):
Expand All @@ -72,7 +84,9 @@
if ATTR_BRIGHTNESS in kwargs and self._lutron_device.is_dimmable:
brightness = kwargs[ATTR_BRIGHTNESS]
elif self._prev_brightness == 0:
brightness = 255 / 2
brightness = self._config_entry.options.get(

Check warning on line 87 in homeassistant/components/lutron/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lutron/light.py#L87

Added line #L87 was not covered by tests
CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL
)
else:
brightness = self._prev_brightness
self._prev_brightness = brightness
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/lutron/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
}
}
},
"options": {
"step": {
"init": {
"data": {
"default_dimmer_level": "Default light level when first turning on a light from Home Assistant"
}
}
}
},
"entity": {
"event": {
"button": {
Expand Down
0