hass_rs/types/
entities.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::fmt;
4
5/// This object represents the Home Assistant Entity
6///
7/// [Entity](https://developers.home-assistant.io/docs/core/entity/)
8#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
9pub struct HassEntity {
10    pub entity_id: String,
11    pub last_changed: String,
12    pub state: String,
13    pub attributes: Value,
14    pub last_updated: String,
15    pub context: Option<Context>, //changed
16}
17
18/// General construct used by HassEntity and HassEvent
19#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
20pub struct Context {
21    pub id: String,
22    pub parent_id: Option<String>,
23    pub user_id: Option<String>,
24}
25
26impl fmt::Display for HassEntity {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        write!(f, "HassEntity {{\n")?;
29        write!(f, "  entity_id: {},\n", self.entity_id)?;
30        write!(f, "  state: {},\n", self.state)?;
31        write!(f, "  last_changed: {},\n", self.last_changed)?;
32        write!(f, "  last_updated: {},\n", self.last_updated)?;
33        write!(f, "  attributes: {:?},\n", self.attributes)?;
34        write!(f, "  context: {:?},\n", self.context)?;
35        write!(f, "}}")?;
36        Ok(())
37    }
38}