mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Remove deprecated fan as light in lutron (#123607)
* Remove deprecated fan as light in lutron * Remove more
This commit is contained in:
parent
a040f1a9d1
commit
4daefe0b6e
@ -82,8 +82,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
elif output.type == "CEILING_FAN_TYPE":
|
||||
entry_data.fans.append((area.name, output))
|
||||
platform = Platform.FAN
|
||||
# Deprecated, should be removed in 2024.8
|
||||
entry_data.lights.append((area.name, output))
|
||||
elif output.is_dimmable:
|
||||
entry_data.lights.append((area.name, output))
|
||||
platform = Platform.LIGHT
|
||||
|
@ -3,12 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from pylutron import Output
|
||||
|
||||
from homeassistant.components.automation import automations_with_entity
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_FLASH,
|
||||
@ -17,23 +15,13 @@ from homeassistant.components.light import (
|
||||
LightEntity,
|
||||
LightEntityFeature,
|
||||
)
|
||||
from homeassistant.components.script import scripts_with_entity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import (
|
||||
IssueSeverity,
|
||||
async_create_issue,
|
||||
create_issue,
|
||||
)
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from .entity import LutronDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@ -45,50 +33,13 @@ async def async_setup_entry(
|
||||
Adds dimmers from the Main Repeater associated with the config_entry as
|
||||
light entities.
|
||||
"""
|
||||
ent_reg = er.async_get(hass)
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
lights = []
|
||||
|
||||
for area_name, device in entry_data.lights:
|
||||
if device.type == "CEILING_FAN_TYPE":
|
||||
# If this is a fan, check to see if this entity already exists.
|
||||
# If not, do not create a new one.
|
||||
entity_id = ent_reg.async_get_entity_id(
|
||||
Platform.LIGHT,
|
||||
DOMAIN,
|
||||
f"{entry_data.client.guid}_{device.uuid}",
|
||||
)
|
||||
if entity_id:
|
||||
entity_entry = ent_reg.async_get(entity_id)
|
||||
assert entity_entry
|
||||
if entity_entry.disabled:
|
||||
# If the entity exists and is disabled then we want to remove
|
||||
# the entity so that the user is using the new fan entity instead.
|
||||
ent_reg.async_remove(entity_id)
|
||||
else:
|
||||
lights.append(LutronLight(area_name, device, entry_data.client))
|
||||
entity_automations = automations_with_entity(hass, entity_id)
|
||||
entity_scripts = scripts_with_entity(hass, entity_id)
|
||||
for item in entity_automations + entity_scripts:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_light_fan_{entity_id}_{item}",
|
||||
breaks_in_ha_version="2024.8.0",
|
||||
is_fixable=True,
|
||||
is_persistent=True,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_light_fan_entity",
|
||||
translation_placeholders={
|
||||
"entity": entity_id,
|
||||
"info": item,
|
||||
},
|
||||
)
|
||||
else:
|
||||
lights.append(LutronLight(area_name, device, entry_data.client))
|
||||
|
||||
async_add_entities(
|
||||
lights,
|
||||
(
|
||||
LutronLight(area_name, device, entry_data.client)
|
||||
for area_name, device in entry_data.lights
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
@ -113,24 +64,8 @@ class LutronLight(LutronDevice, LightEntity):
|
||||
_prev_brightness: int | None = None
|
||||
_attr_name = None
|
||||
|
||||
def __init__(self, area_name, lutron_device, controller) -> None:
|
||||
"""Initialize the light."""
|
||||
super().__init__(area_name, lutron_device, controller)
|
||||
self._is_fan = lutron_device.type == "CEILING_FAN_TYPE"
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the light on."""
|
||||
if self._is_fan:
|
||||
create_issue(
|
||||
self.hass,
|
||||
DOMAIN,
|
||||
"deprecated_light_fan_on",
|
||||
breaks_in_ha_version="2024.8.0",
|
||||
is_fixable=True,
|
||||
is_persistent=True,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_light_fan_on",
|
||||
)
|
||||
if flash := kwargs.get(ATTR_FLASH):
|
||||
self._lutron_device.flash(0.5 if flash == "short" else 1.5)
|
||||
else:
|
||||
@ -148,17 +83,6 @@ class LutronLight(LutronDevice, LightEntity):
|
||||
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the light off."""
|
||||
if self._is_fan:
|
||||
create_issue(
|
||||
self.hass,
|
||||
DOMAIN,
|
||||
"deprecated_light_fan_off",
|
||||
breaks_in_ha_version="2024.8.0",
|
||||
is_fixable=True,
|
||||
is_persistent=True,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_light_fan_off",
|
||||
)
|
||||
args = {"new_level": 0}
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
args["fade_time_seconds"] = kwargs[ATTR_TRANSITION]
|
||||
|
@ -36,19 +36,5 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_light_fan_entity": {
|
||||
"title": "Detected Lutron fan entity created as a light",
|
||||
"description": "Fan entities have been added to the Lutron integration.\nWe detected that entity `{entity}` is being used in `{info}`\n\nWe have created a new fan entity and you should migrate `{info}` to use this new entity.\n\nWhen you are done migrating `{info}` and are ready to have the deprecated light entity removed, disable the entity and restart Home Assistant."
|
||||
},
|
||||
"deprecated_light_fan_on": {
|
||||
"title": "The Lutron integration deprecated fan turned on",
|
||||
"description": "Fan entities have been added to the Lutron integration.\nPreviously fans were created as lights; this behavior is now deprecated.\n\nYour configuration just turned on a fan created as a light. You should migrate your scenes and automations to use the new fan entity.\n\nWhen you are done migrating your automations and are ready to have the deprecated light entity removed, disable the entity and restart Home Assistant.\n\nAn issue will be created each time the incorrect entity is used to remind you to migrate."
|
||||
},
|
||||
"deprecated_light_fan_off": {
|
||||
"title": "The Lutron integration deprecated fan turned off",
|
||||
"description": "Fan entities have been added to the Lutron integration.\nPreviously fans were created as lights; this behavior is now deprecated.\n\nYour configuration just turned off a fan created as a light. You should migrate your scenes and automations to use the new fan entity.\n\nWhen you are done migrating your automations and are ready to have the deprecated light entity removed, disable the entity and restart Home Assistant.\n\nAn issue will be created each time the incorrect entity is used to remind you to migrate."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user