syntax = "proto2";

package aiobafi6;

message Root { optional Root2 root2 = 2; }

message Root2 {
  optional Commit commit = 2;
  optional Query query = 3;
  optional QueryResult query_result = 4;
}

message Commit { optional Properties properties = 3; }

enum ProperyQuery {
  ALL = 0;
  FAN = 1;
  LIGHT = 2;
  FIRMWARE_MORE_DATETIME_API = 3;
  NETWORK = 4;
  SCHEDULES = 5;
  SENSORS = 6;
}

message Query { optional ProperyQuery property_query = 1; }

message QueryResult {
  repeated Properties properties = 2;
  repeated Schedule schedules = 3;
}

enum OffOnAuto {
  OFF = 0;
  ON = 1;
  AUTO = 2;
}

message Properties {
  // General
  optional string name = 1;
  optional string model = 2;
  optional string local_datetime = 4; // ISO 8601
  optional string utc_datetime = 5;   // ISO 8601
  optional string firmware_version = 7;
  optional string mac_address = 8;

  // API
  optional string uuid9 = 9;
  optional string dns_sd_uuid = 10; // uuid used for _api._tcp dns service
  optional string api_endpoint = 11;
  optional string api_version = 13;

  optional FirmwareProperties firmware = 16;
  optional Capabilities capabilities = 17;

  // Fan
  optional OffOnAuto fan_mode = 43;
  optional bool reverse_enable = 44;
  optional int32 speed_percent = 45; // 0-100
  optional int32 speed = 46;         // 0-7

  optional bool whoosh_enable = 58;
  optional bool eco_enable = 65;

  optional bool auto_comfort_enable = 47;
  optional int32 comfort_ideal_temperature = 48; // divide by 100.0, in ºC
  optional bool comfort_heat_assist_enable = 60;
  optional int32 comfort_heat_assist_speed = 61;
  optional bool comfort_heat_assist_reverse_enable = 62;
  optional int32 comfort_min_speed = 50; // 0 for no min
  optional int32 comfort_max_speed = 51; // 7 for no max

  optional bool motion_sense_enable = 52;
  optional int32 motion_sense_timeout = 53; // in s

  optional bool return_to_auto_enable = 54;
  optional int32 return_to_auto_timeout = 55; // in s

  optional int32 target_rpm = 63;
  optional int32 current_rpm = 64;

  // Resets after about 4 minutes 30 seconds.
  // Speculatively placed in the fan category as it is returned with other
  // fan properties by the firmware. Arguably could be named "fast occupancy".
  optional bool fan_occupancy_detected = 66; // `api_version` >= 5

  // Light
  optional OffOnAuto light_mode = 68;
  optional int32 light_brightness_percent = 69; // 0-100
  optional int32 light_brightness_level = 70;   // 0-16
  optional int32 light_color_temperature = 71;

  optional bool light_dim_to_warm_enable = 77;

  optional int32 light_auto_motion_timeout = 73;

  optional bool light_return_to_auto_enable = 74;
  optional int32 light_return_to_auto_timeout = 75;

  optional int32 light_warmest_color_temperature = 78;
  optional int32 light_coolest_color_temperature = 79;

  // Resets after about 9 minutes 30 seconds.
  // Speculatively placed in the light category as it is returned with other
  // light properties by the firmware. Arguably could be named "slow occupancy".
  // And given its field ID, it's odd that it's not in the sensor category.
  optional bool light_occupancy_detected = 85; // `api_version` >= 5

  // Sensors

  optional int32 temperature = 86; // divide by 100.0, in ºC
  optional int32 humidity = 87;    // percent

  // Connectivity
  optional string ip_address = 120;
  optional WifiProperties wifi = 124;

  // More
  optional bool led_indicators_enable = 134;
  optional bool fan_beep_enable = 135;
  optional bool legacy_ir_remote_enable = 136;

  // Controls
  optional FirmwareProperties remote_firmware = 152;

  // Speculatively called stats because it contains uptime.
  optional Stats stats = 156;
}

message FirmwareProperties {
  optional string firmware_version = 2;
  optional string bootloader_version = 3;
  optional string mac_address = 4;
}

message Capabilities {
  optional bool has_comfort1 = 1;
  optional bool has_comfort3 = 3;
  optional bool has_light = 4;
}

message WifiProperties { optional string ssid = 1; }

message Schedule {}

message Stats { optional int32 uptime_minutes = 1; }
