Skip to main content

Module esphomeserver

Module esphomeserver 

Source
Expand description

High-level ESPHome server implementation with entity management.

This module provides the EspHomeServer abstraction, which simplifies working with ESPHome devices by managing entities. It builds on top of the lower-level crate::esphomeapi::EspHomeApi and handles entity registration and message routing automatically.

§Examples

use esphome_native_api::esphomeserver::{EspHomeServer, Entity, BinarySensor};
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let stream = TcpStream::connect("192.168.1.100:6053").await?;
     
    let mut server = EspHomeServer::builder()
        .name("my-server".to_string())
        .build();
     
    // Add entities
    let sensor = Entity::BinarySensor(BinarySensor {
        object_id: "door_sensor".to_string(),
    });
    server.add_entity("door_sensor", sensor);
     
    let (tx, mut rx) = server.start(stream).await?;
     
    Ok(())
}

Structs§

BinarySensor
Represents a binary sensor entity.
EspHomeServer
High-level ESPHome server implementation.

Enums§

Entity
Represents different types of entities supported by ESPHome.