You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6KB

  1. use qmetaobject::*;
  2. #[derive(QObject, Default)]
  3. pub struct RadiateLight {
  4. base: qt_base_class!(trait QObject),
  5. name: qt_property!(String; NOTIFY name_changed),
  6. name_changed: qt_signal!(),
  7. state: qt_property!(RadiateLightState; NOTIFY state_changed),
  8. state_changed: qt_signal!(),
  9. ct_min: qt_property!(u16; NOTIFY ct_min_changed),
  10. ct_min_changed: qt_signal!(),
  11. ct_max: qt_property!(u16; NOTIFY ct_max_changed),
  12. ct_max_changed: qt_signal!(),
  13. }
  14. #[derive(QGadget, Default, Clone)]
  15. pub struct RadiateLightState {
  16. on: qt_property!(bool),
  17. bri: qt_property!(u8),
  18. ct_valid: qt_property!(bool),
  19. ct: qt_property!(u16),
  20. color: qt_property!(RadiateLightColorState),
  21. }
  22. #[derive(QGadget, Default, Clone)]
  23. pub struct RadiateLightColorState {
  24. valid: qt_property!(bool),
  25. hue: qt_property!(u16),
  26. sat: qt_property!(u8),
  27. }
  28. impl From<&huey::connection::Light> for RadiateLight {
  29. fn from(light: &huey::connection::Light) -> Self {
  30. let mut result: Self = Default::default();
  31. result.name = light.name.clone();
  32. if let Some(ref cap) = light.capabilities.control.ct {
  33. result.ct_min = cap.min;
  34. result.ct_max = cap.max;
  35. } else {
  36. result.ct_min = 233;
  37. result.ct_max = 233;
  38. }
  39. result.state.on = light.state.on;
  40. result.state.bri = light.state.bri;
  41. if let Some(ref color) = light.state.color {
  42. result.state.color.valid = true;
  43. result.state.color.hue = color.hue;
  44. result.state.color.sat = color.sat;
  45. }
  46. if let Some(ct) = light.state.ct {
  47. result.state.ct_valid = true;
  48. result.state.ct = ct;
  49. } else {
  50. result.state.ct_valid = false;
  51. result.state.ct = 233; // probably doesn't matter anyway
  52. }
  53. result
  54. }
  55. }
  56. #[derive(QObject, Default)]
  57. pub struct RadiateGroup {
  58. base: qt_base_class!(trait QObject),
  59. name: qt_property!(String; NOTIFY name_changed),
  60. name_changed: qt_signal!(),
  61. action: qt_property!(RadiateLightState; NOTIFY state_changed),
  62. state_changed: qt_signal!(),
  63. }
  64. impl From<&huey::connection::LightGroup> for RadiateGroup {
  65. fn from(group: &huey::connection::LightGroup) -> Self {
  66. let mut result = Self::default();
  67. result.name = group.name.clone();
  68. result.action.on = group.action.on;
  69. result.action.bri = group.action.bri;
  70. if let Some(ref color) = group.action.color {
  71. result.action.color.valid = true;
  72. result.action.color.hue = color.hue;
  73. result.action.color.sat = color.sat;
  74. }
  75. result
  76. }
  77. }