Skip to content

Commit 482b5d4

Browse files
authored
Introduce Home Assistant Labs (home-assistant#156840)
1 parent 126fd21 commit 482b5d4

File tree

22 files changed

+1832
-2
lines changed

22 files changed

+1832
-2
lines changed

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

homeassistant/bootstrap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
STAGE_0_INTEGRATIONS = (
177177
# Load logging and http deps as soon as possible
178178
("logging, http deps", LOGGING_AND_HTTP_DEPS_INTEGRATIONS, None),
179+
# Setup labs for preview features
180+
("labs", {"labs"}, STAGE_0_SUBSTAGE_TIMEOUT),
179181
# Setup frontend
180182
("frontend", FRONTEND_INTEGRATIONS, None),
181183
# Setup recorder
@@ -212,6 +214,7 @@
212214
"backup",
213215
"frontend",
214216
"hardware",
217+
"labs",
215218
"logger",
216219
"network",
217220
"system_health",

homeassistant/components/kitchen_sink/__init__.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
import voluptuous as vol
1313

14+
from homeassistant.components.labs import (
15+
EVENT_LABS_UPDATED,
16+
EventLabsUpdatedData,
17+
async_is_preview_feature_enabled,
18+
)
1419
from homeassistant.components.recorder import DOMAIN as RECORDER_DOMAIN, get_instance
1520
from homeassistant.components.recorder.models import (
1621
StatisticData,
@@ -30,10 +35,14 @@
3035
UnitOfTemperature,
3136
UnitOfVolume,
3237
)
33-
from homeassistant.core import HomeAssistant, ServiceCall, callback
38+
from homeassistant.core import Event, HomeAssistant, ServiceCall, callback
3439
from homeassistant.helpers import config_validation as cv
3540
from homeassistant.helpers.device_registry import DeviceEntry
36-
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
41+
from homeassistant.helpers.issue_registry import (
42+
IssueSeverity,
43+
async_create_issue,
44+
async_delete_issue,
45+
)
3746
from homeassistant.helpers.typing import ConfigType
3847
from homeassistant.util import dt as dt_util
3948
from homeassistant.util.unit_conversion import (
@@ -110,6 +119,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
110119
# Notify backup listeners
111120
hass.async_create_task(_notify_backup_listeners(hass), eager_start=False)
112121

122+
# Subscribe to labs feature updates for kitchen_sink preview repair
123+
@callback
124+
def _async_labs_updated(event: Event[EventLabsUpdatedData]) -> None:
125+
"""Handle labs feature update event."""
126+
if (
127+
event.data["domain"] == "kitchen_sink"
128+
and event.data["preview_feature"] == "special_repair"
129+
):
130+
_async_update_special_repair(hass)
131+
132+
entry.async_on_unload(
133+
hass.bus.async_listen(EVENT_LABS_UPDATED, _async_labs_updated)
134+
)
135+
136+
# Check if lab feature is currently enabled and create repair if so
137+
_async_update_special_repair(hass)
138+
113139
return True
114140

115141

@@ -137,6 +163,27 @@ async def async_remove_config_entry_device(
137163
return True
138164

139165

166+
@callback
167+
def _async_update_special_repair(hass: HomeAssistant) -> None:
168+
"""Create or delete the special repair issue.
169+
170+
Creates a repair issue when the special_repair lab feature is enabled,
171+
and deletes it when disabled. This demonstrates how lab features can interact
172+
with Home Assistant's repair system.
173+
"""
174+
if async_is_preview_feature_enabled(hass, DOMAIN, "special_repair"):
175+
async_create_issue(
176+
hass,
177+
DOMAIN,
178+
"kitchen_sink_special_repair_issue",
179+
is_fixable=False,
180+
severity=IssueSeverity.WARNING,
181+
translation_key="special_repair",
182+
)
183+
else:
184+
async_delete_issue(hass, DOMAIN, "kitchen_sink_special_repair_issue")
185+
186+
140187
async def _notify_backup_listeners(hass: HomeAssistant) -> None:
141188
for listener in hass.data.get(DATA_BACKUP_AGENT_LISTENERS, []):
142189
listener()

homeassistant/components/kitchen_sink/manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"codeowners": ["@home-assistant/core"],
66
"documentation": "https://www.home-assistant.io/integrations/kitchen_sink",
77
"iot_class": "calculated",
8+
"preview_features": {
9+
"special_repair": {
10+
"feedback_url": "https://community.home-assistant.io",
11+
"learn_more_url": "https://www.home-assistant.io/integrations/kitchen_sink",
12+
"report_issue_url": "https://github.com/home-assistant/core/issues/new?template=bug_report.yml&integration_link=https://www.home-assistant.io/integrations/kitchen_sink&integration_name=Kitchen%20Sink"
13+
}
14+
},
815
"quality_scale": "internal",
916
"single_config_entry": true
1017
}

homeassistant/components/kitchen_sink/strings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
},
7272
"title": "The blinker fluid is empty and needs to be refilled"
7373
},
74+
"special_repair": {
75+
"description": "This is a special repair created by a preview feature! This demonstrates how lab features can interact with the Home Assistant repair system. You can disable this by turning off the kitchen sink special repair feature in Settings > System > Labs.",
76+
"title": "Special repair feature preview"
77+
},
7478
"transmogrifier_deprecated": {
7579
"description": "The transmogrifier component is now deprecated due to the lack of local control available in the new API",
7680
"title": "The transmogrifier component is deprecated"
@@ -103,6 +107,14 @@
103107
}
104108
}
105109
},
110+
"preview_features": {
111+
"special_repair": {
112+
"description": "Creates a **special repair issue** when enabled.\n\nThis demonstrates how lab features can interact with other Home Assistant integrations.",
113+
"disable_confirmation": "This will remove the special repair issue. Don't worry, this is just a demonstration feature.",
114+
"enable_confirmation": "This will create a special repair issue to demonstrate Labs preview features. This is just an example and won't affect your actual system.",
115+
"name": "Special repair"
116+
}
117+
},
106118
"services": {
107119
"test_service_1": {
108120
"description": "Fake action for testing",

0 commit comments

Comments
 (0)