use crate::resource::{self, Alert, Effect, ModifierType};
use crate::Color;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub struct Group {
#[serde(skip)]
pub id: String,
pub name: String,
pub lights: Vec<String>,
pub sensors: Vec<String>,
#[serde(rename = "type")]
pub kind: Kind,
pub class: Option<Class>,
pub state: Option<State>,
#[serde(rename = "modelid")]
pub model_id: Option<String>,
#[serde(rename = "unique_id")]
pub unique_id: Option<String>,
pub recycle: Option<bool>,
}
impl resource::Resource for Group {}
impl Group {
pub(crate) fn with_id(mut self, id: impl Into<String>) -> Self {
self.id = id.into();
self
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
#[serde(untagged)]
pub enum Kind {
Creatable(CreatableKind),
Immutable(ImmutableKind),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum CreatableKind {
LightGroup,
Room,
Entertainment,
Zone,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
pub enum ImmutableKind {
Zero,
Luminaire,
#[serde(rename = "Lightsource")]
LightSource,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum Class {
Attic,
Balcony,
Barbecue,
Bathroom,
Bedroom,
Carport,
Closet,
Computer,
Dining,
Downstairs,
Driveway,
#[serde(rename = "Front door")]
FrontDoor,
Garage,
Garden,
#[serde(rename = "Guest room")]
GuestRoom,
Gym,
Hallway,
Home,
#[serde(rename = "Kids bedroom")]
KidsBedroom,
Kitchen,
#[serde(rename = "Laundry room")]
LaundryRoom,
#[serde(rename = "Living room")]
LivingRoom,
Lounge,
#[serde(rename = "Man cave")]
ManCave,
Music,
Nursery,
Office,
Other,
Pool,
Porch,
Reading,
Recreation,
Staircase,
Storage,
Studio,
TV,
Terrace,
Toilet,
#[serde(rename = "Top floor")]
TopFloor,
Upstairs,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
pub struct State {
pub any_on: bool,
pub all_on: bool,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct Creator {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
lights: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
sensors: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none", rename = "type")]
kind: Option<CreatableKind>,
#[serde(skip_serializing_if = "Option::is_none")]
class: Option<Class>,
#[serde(skip_serializing_if = "Option::is_none")]
recycle: Option<bool>,
}
impl resource::Creator for Creator {}
impl Creator {
pub fn new(name: impl Into<String>, lights: Vec<impl Into<String>>) -> Self {
Self {
name: Some(name.into()),
lights: Some(lights.into_iter().map(|v| v.into()).collect()),
..Default::default()
}
}
pub fn sensors(mut self, value: Vec<impl Into<String>>) -> Self {
self.sensors = Some(value.into_iter().map(|v| v.into()).collect());
self
}
pub fn kind(mut self, value: CreatableKind) -> Self {
self.kind = Some(value);
self
}
pub fn class(mut self, value: Class) -> Self {
self.class = Some(value);
self
}
pub fn recycle(mut self, value: bool) -> Self {
self.recycle = Some(value);
self
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct AttributeModifier {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
lights: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
sensors: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
class: Option<Class>,
}
impl resource::Modifier for AttributeModifier {}
impl AttributeModifier {
pub fn name(mut self, value: impl Into<String>) -> Self {
self.name = Some(value.into());
self
}
pub fn lights(mut self, value: Vec<impl Into<String>>) -> Self {
self.lights = Some(value.into_iter().map(|v| v.into()).collect());
self
}
pub fn sensors(mut self, value: Vec<impl Into<String>>) -> Self {
self.sensors = Some(value.into_iter().map(|v| v.into()).collect());
self
}
pub fn class(mut self, value: Class) -> Self {
self.class = Some(value);
self
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
pub struct StateModifier {
#[serde(skip_serializing_if = "Option::is_none")]
on: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", rename = "bri")]
brightness: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
hue: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "sat")]
saturation: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none", rename = "xy")]
color_space_coordinates: Option<(f32, f32)>,
#[serde(skip_serializing_if = "Option::is_none", rename = "ct")]
color_temperature: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
alert: Option<Alert>,
#[serde(skip_serializing_if = "Option::is_none")]
effect: Option<Effect>,
#[serde(skip_serializing_if = "Option::is_none", rename = "transitiontime")]
transition_time: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "bri_inc")]
brightness_increment: Option<i16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "hue_inc")]
hue_increment: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", rename = "sat_inc")]
saturation_increment: Option<i16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "xy_inc")]
color_space_coordinates_increment: Option<(f32, f32)>,
#[serde(skip_serializing_if = "Option::is_none", rename = "ct_inc")]
color_temperature_increment: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
scene: Option<String>,
}
impl resource::Modifier for StateModifier {}
impl StateModifier {
pub fn on(mut self, value: bool) -> Self {
self.on = Some(value);
self
}
pub fn brightness(mut self, modifier_type: ModifierType, value: u8) -> Self {
match modifier_type {
ModifierType::Override => self.brightness = Some(value),
ModifierType::Increment => self.brightness_increment = Some(value as i16),
ModifierType::Decrement => self.brightness_increment = Some(-(value as i16)),
};
self
}
pub fn hue(mut self, modifier_type: ModifierType, value: u16) -> Self {
match modifier_type {
ModifierType::Override => self.hue = Some(value),
ModifierType::Increment => self.hue_increment = Some(value as i32),
ModifierType::Decrement => self.hue_increment = Some(-(value as i32)),
};
self
}
pub fn saturation(mut self, modifier_type: ModifierType, value: u8) -> Self {
match modifier_type {
ModifierType::Override => self.saturation = Some(value),
ModifierType::Increment => self.saturation_increment = Some(value as i16),
ModifierType::Decrement => self.saturation_increment = Some(-(value as i16)),
};
self
}
pub fn color(mut self, value: Color) -> Self {
self.color_space_coordinates = Some(value.space_coordinates);
if let Some(v) = value.brightness {
self.brightness = Some(v);
}
self
}
pub fn color_temperature(mut self, modifier_type: ModifierType, value: u16) -> Self {
match modifier_type {
ModifierType::Override => self.color_temperature = Some(value),
ModifierType::Increment => self.color_temperature_increment = Some(value as i32),
ModifierType::Decrement => self.color_temperature_increment = Some(-(value as i32)),
};
self
}
pub fn alert(mut self, value: Alert) -> Self {
self.alert = Some(value);
self
}
pub fn effect(mut self, value: Effect) -> Self {
self.effect = Some(value);
self
}
pub fn transition_time(mut self, value: u16) -> Self {
self.transition_time = Some(value);
self
}
pub fn scene(mut self, value: impl Into<String>) -> Self {
self.scene = Some(value.into());
self
}
}