-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Introduce Home Assistant Labs #156840
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
Introduce Home Assistant Labs #156840
Changes from all commits
aa522ff
fe23b0a
30c72f4
d85cf6a
d678e4a
b8d7192
3cf100c
e51b914
2270859
3e1e4d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,11 @@ | |
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.labs import ( | ||
| EVENT_LABS_UPDATED, | ||
| EventLabsUpdatedData, | ||
| async_is_preview_feature_enabled, | ||
| ) | ||
| from homeassistant.components.recorder import DOMAIN as RECORDER_DOMAIN, get_instance | ||
| from homeassistant.components.recorder.models import ( | ||
| StatisticData, | ||
|
|
@@ -30,10 +35,14 @@ | |
| UnitOfTemperature, | ||
| UnitOfVolume, | ||
| ) | ||
| from homeassistant.core import HomeAssistant, ServiceCall, callback | ||
| from homeassistant.core import Event, HomeAssistant, ServiceCall, callback | ||
| from homeassistant.helpers import config_validation as cv | ||
| from homeassistant.helpers.device_registry import DeviceEntry | ||
| from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue | ||
| from homeassistant.helpers.issue_registry import ( | ||
| IssueSeverity, | ||
| async_create_issue, | ||
| async_delete_issue, | ||
| ) | ||
| from homeassistant.helpers.typing import ConfigType | ||
| from homeassistant.util import dt as dt_util | ||
| from homeassistant.util.unit_conversion import ( | ||
|
|
@@ -110,6 +119,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |
| # Notify backup listeners | ||
| hass.async_create_task(_notify_backup_listeners(hass), eager_start=False) | ||
|
|
||
| # Subscribe to labs feature updates for kitchen_sink preview repair | ||
| @callback | ||
| def _async_labs_updated(event: Event[EventLabsUpdatedData]) -> None: | ||
| """Handle labs feature update event.""" | ||
| if ( | ||
| event.data["domain"] == "kitchen_sink" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have to, it is typed already.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry the domain constant using kitchen_sink; yeah sure 👍 |
||
| and event.data["preview_feature"] == "special_repair" | ||
| ): | ||
| _async_update_special_repair(hass) | ||
|
|
||
| entry.async_on_unload( | ||
| hass.bus.async_listen(EVENT_LABS_UPDATED, _async_labs_updated) | ||
| ) | ||
|
|
||
| # Check if lab feature is currently enabled and create repair if so | ||
| _async_update_special_repair(hass) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
|
|
@@ -137,6 +163,27 @@ async def async_remove_config_entry_device( | |
| return True | ||
|
|
||
|
|
||
| @callback | ||
| def _async_update_special_repair(hass: HomeAssistant) -> None: | ||
| """Create or delete the special repair issue. | ||
|
|
||
| Creates a repair issue when the special_repair lab feature is enabled, | ||
| and deletes it when disabled. This demonstrates how lab features can interact | ||
| with Home Assistant's repair system. | ||
| """ | ||
| if async_is_preview_feature_enabled(hass, DOMAIN, "special_repair"): | ||
| async_create_issue( | ||
| hass, | ||
| DOMAIN, | ||
| "kitchen_sink_special_repair_issue", | ||
| is_fixable=False, | ||
| severity=IssueSeverity.WARNING, | ||
| translation_key="special_repair", | ||
| ) | ||
| else: | ||
| async_delete_issue(hass, DOMAIN, "kitchen_sink_special_repair_issue") | ||
|
|
||
|
|
||
| async def _notify_backup_listeners(hass: HomeAssistant) -> None: | ||
| for listener in hass.data.get(DATA_BACKUP_AGENT_LISTENERS, []): | ||
| listener() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this API could be simplified a bit by creating a helper function to create this listener function.
I'm thinking of something similar to the one below.
This way, the integration author does not have to wonder whether Futures Lab uses the event bus and what the message format is.
This will slightly extend the existing public API we currently have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we tend to avoid using core events nowadays for things that aren't user facing.