Files
smart-home-in-rust-with-hom…/home-assistant/src/light/service/turn_off.rs

34 lines
1.1 KiB
Rust

use std::str::FromStr;
use pyo3::IntoPyObject;
use crate::{
domain::Domain, entity_id::EntityId, object_id::ObjectId, service::{IntoServiceCall, service_domain::ServiceDomain, service_id::ServiceId}
};
#[derive(Debug, Clone)]
pub struct TurnOff {
pub object_id: ObjectId,
}
#[derive(Debug, Clone, IntoPyObject)]
pub struct TurnOffServiceData {
entity_id: EntityId,
}
impl IntoServiceCall for TurnOff {
type ServiceData = TurnOffServiceData;
fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) {
let service_domain = ServiceDomain::from_str("light").expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future");
let service_id = ServiceId::from_str("turn_off").expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future");
let Self { object_id } = self;
let entity_id = EntityId(Domain::Light, object_id);
let service_data = TurnOffServiceData { entity_id };
(service_domain, service_id, service_data)
}
}