// Contains definitions specific to sensors.
//
// Copyright:
// Copyright 2022 Frequenz Energy-as-a-Service GmbH
//
// License:
// MIT

syntax = "proto3";

package frequenz.api.microgrid.sensor;

import "frequenz/api/microgrid/common.proto";

import "frequenz/api/common/components.proto";

// The sensor metadata.
message Metadata {
  // The sensor type.
  frequenz.api.common.components.SensorType type = 1;
}

// Enumerated sensor states.
enum ComponentState {
  // Unspecified state.
  COMPONENT_STATE_UNSPECIFIED = 0;

  // The sensor is behaving as expected.
  COMPONENT_STATE_OK = 1;

  // The sensor is in an error state.
  COMPONENT_STATE_ERROR = 2;
}

// Enumerated sensor error codes.
enum ErrorCode {
  // Unspecified.
  ERROR_CODE_UNSPECIFIED = 0;
}

// The type of the metric reported in a sensor data sample.
enum SensorMetric {
  // Unspecified.
  SENSOR_METRIC_UNSPECIFIED = 0;

  // Temperature.
  // In Celsius (°C).
  SENSOR_METRIC_TEMPERATURE = 1;

  // Humidity
  // In percentage (%).
  SENSOR_METRIC_HUMIDITY = 2;

  // Pressure
  // In Pascal (Pa).
  SENSOR_METRIC_PRESSURE = 3;

  // Irradiance / Radiation flux
  // In watts per square meter (W / m^2).
  SENSOR_METRIC_IRRADIANCE = 4;

  // Velocity
  // In meters per second (m / s).
  SENSOR_METRIC_VELOCITY = 5;

  // Acceleration.
  // In meters per second per second (m / s^2)
  SENSOR_METRIC_ACCELERATION = 6;

  // Metric to represent angles, for metrics like direction.
  // In angles with respect to the (magnetic) North (°).
  SENSOR_METRIC_ANGLE = 7;

  // Dew point.
  // The temperature at which the air becomes saturated with water vapor.
  //
  // In Celsius (°C).
  SENSOR_METRIC_DEW_POINT = 8;
}

// State message.
message State {
  // The state of the overall component.
  ComponentState component_state = 1;
}

// Error message.
message Error {
  // The error code.
  ErrorCode code = 1;

  // The error severity level.
  common.ErrorLevel level = 2;

  // The error message.
  string msg = 3;
}

// A value of a single metric.
message SensorData {
  // The metric value.
  float value = 1;

  // The metric name.
  SensorMetric sensor_metric = 2;
}

// Sensor data.
message Data {
  // AC metrics of the inverter.
  repeated SensorData sensor_data = 1;
}

// Sensor properties.
message Properties {
  // The firmware version of the component.
  string firmware_ver = 1;
}

// Sensor details
message Sensor {
  // The component properties
  Properties properties = 1;

  // The sensor's state.
  State state = 2;

  // A list of errors encountered the component. An empty list implies no error.
  repeated Error errors = 3;

  // Sensor data object.
  Data data = 4;
}
