|
- use qmetaobject::*;
-
- #[derive(QObject, Default)]
- pub struct RadiateLight {
- base: qt_base_class!(trait QObject),
- name: qt_property!(String; NOTIFY name_changed),
- name_changed: qt_signal!(),
- state: qt_property!(RadiateLightState; NOTIFY state_changed),
- state_changed: qt_signal!(),
-
- ct_min: qt_property!(u16; NOTIFY ct_min_changed),
- ct_min_changed: qt_signal!(),
- ct_max: qt_property!(u16; NOTIFY ct_max_changed),
- ct_max_changed: qt_signal!(),
- }
-
- #[derive(QGadget, Default, Clone)]
- pub struct RadiateLightState {
- on: qt_property!(bool),
- bri: qt_property!(u8),
-
- ct_valid: qt_property!(bool),
- ct: qt_property!(u16),
-
- color: qt_property!(RadiateLightColorState),
- }
-
- #[derive(QGadget, Default, Clone)]
- pub struct RadiateLightColorState {
- valid: qt_property!(bool),
- hue: qt_property!(u16),
- sat: qt_property!(u8),
- }
-
- impl From<&huey::connection::Light> for RadiateLight {
- fn from(light: &huey::connection::Light) -> Self {
- let mut result: Self = Default::default();
- result.name = light.name.clone();
-
- if let Some(ref cap) = light.capabilities.control.ct {
- result.ct_min = cap.min;
- result.ct_max = cap.max;
- } else {
- result.ct_min = 233;
- result.ct_max = 233;
- }
-
- result.state.on = light.state.on;
- result.state.bri = light.state.bri;
- if let Some(ref color) = light.state.color {
- result.state.color.valid = true;
- result.state.color.hue = color.hue;
- result.state.color.sat = color.sat;
- }
- if let Some(ct) = light.state.ct {
- result.state.ct_valid = true;
- result.state.ct = ct;
- } else {
- result.state.ct_valid = false;
- result.state.ct = 233; // probably doesn't matter anyway
- }
-
- result
- }
- }
-
- #[derive(QObject, Default)]
- pub struct RadiateGroup {
- base: qt_base_class!(trait QObject),
- name: qt_property!(String; NOTIFY name_changed),
- name_changed: qt_signal!(),
- action: qt_property!(RadiateLightState; NOTIFY state_changed),
- state_changed: qt_signal!(),
- }
-
- impl From<&huey::connection::LightGroup> for RadiateGroup {
- fn from(group: &huey::connection::LightGroup) -> Self {
- let mut result = Self::default();
- result.name = group.name.clone();
- result.action.on = group.action.on;
- result.action.bri = group.action.bri;
- if let Some(ref color) = group.action.color {
- result.action.color.valid = true;
- result.action.color.hue = color.hue;
- result.action.color.sat = color.sat;
- }
-
- result
- }
- }
|