Skip to main content

HomeCorePlugin

Trait HomeCorePlugin 

Source
pub trait HomeCorePlugin:
    Send
    + Sync
    + 'static {
    // Required methods
    fn setup<'life0, 'async_trait>(
        &'life0 self,
        hc: HomeCore,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn unload<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn state_changed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _event: &'life1 StateChangedEventJson,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Lifecycle trait that every HOMECORE integration must implement.

Implementing types are passed to [PluginRuntime::load]; the runtime calls these methods at the appropriate lifecycle points.

§Async

Both methods are async to allow network / IO initialisation without blocking the Tokio runtime. The async_trait macro erases the impl return type so it works in trait objects.

Required Methods§

Source

fn setup<'life0, 'async_trait>( &'life0 self, hc: HomeCore, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called once when the plugin’s config entry is being set up.

The plugin receives a reference to the HomeCore runtime and should register its entities, services, and event subscriptions here.

Source

fn unload<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the plugin is being removed from the registry.

The plugin should clean up subscriptions and deregister its entities.

Provided Methods§

Source

fn state_changed<'life0, 'life1, 'async_trait>( &'life0 self, _event: &'life1 StateChangedEventJson, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Receive a committed state change. The default is a no-op so built-in plugins only opt into event work they need.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§