oc2_hlapi_v2 0.2.0

A client for the new version of OpenComputers II's HLAPI
Documentation
use std::convert::Infallible;

use uuid::Uuid;

use crate::client::{DeviceBase, HlapiClient, HlapiClientError};

#[derive(Debug, Clone)]
/// A spawner device
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/spawner.html)
pub struct Spawner {
    client: HlapiClient,
    uuid: Uuid,
}

impl Spawner {
    /// Gets what entity the spawner spawns next. [`None`] if the spawner has no set entity.
    pub fn get_entity_type(&self) -> Result<Option<String>, HlapiClientError> {
        Ok(self.call("getEntityType", &[], &[])?.0)
    }
}

impl DeviceBase for Spawner {
    const TYPE: &'static str = "spawner";

    type Event = Infallible;

    fn new(client: HlapiClient, uuid: Uuid) -> Result<Self, HlapiClientError> {
        Ok(Self { client, uuid })
    }

    fn uuid_base(&self) -> Uuid {
        self.uuid
    }

    fn client(&self) -> &HlapiClient {
        &self.client
    }
}