# frozen_string_literal: true module DjiMqttConnect module Thing::Product class DockOsdMessage < OsdMessage STABLE_DATA_ATTRIBUTES = %i[ drc_state drone_in_dock job_number ] # {"0":"Idle mode (No cooling, heating, and dehumidification)","1":"Cooling mode","2":"Heating mode","3":"Dehumidification mode","4":"Cooling exit mode","5":"Heating exit mode","6":"Dehumidification exit mode","7":"Cooling preparation mode","8":"Heating preparation mode","9":"Dehumidification preparation mode"} AirConditionerState = Types::Integer.enum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) attribute :data do include Mixins::LatitudeConditional include Mixins::LongitudeConditional include Mixins::TemperatureConditional attribute? :acc_time, Types::Integer attribute? :activation_time, Types::Integer attribute? :backup_battery do include Mixins::TemperatureConditional attribute :switch, Types::Integer.enum(0, 1) attribute :voltage, Types::Integer attribute :temperature, Types::Temperature end # {"0":"Disconnected","1":"Connecting","2":"Connected"} attribute? :drc_state, Types::Integer.enum(0, 1, 2) attribute? :drone_battery_maintenance_info do attribute :batteries, Types::Array do include Mixins::TemperatureConditional attribute :index, Types::Integer attribute :capacity_percent, Types::Integer attribute :voltage, Types::Integer attribute :temperature, Types::Temperature end # {"0":"Battery is not in heating or insulation","1":"Battery is in heating","2":"Battery is in insulation"} attribute? :heat_state, Types::Integer.enum(0, 1, 2) # {"0":"No need to maintenance","1":"Need maintenance","2":"Under maintenance"} attribute? :maintenance_state, Types::Integer attribute? :maintenance_time_left, Types::Integer end attribute? :drone_charge_state do # {"0":"not charging","1":"charging"} attribute :state, Types::Integer.enum( STATE_NOT_CHARGING = 0, STATE_CHARGING = 1 ) def humanized_state state_key = case state when STATE_NOT_CHARGING "Not Charging" when STATE_CHARGING "Charging" end I18n.t(state_key.parameterize.underscore, scope: "dji_mqtt_connect.dock_drone_charge_state.state", default: state_key) end # {"min":"0","max":"100"} attribute :capacity_percent, Types::Integer.constrained(gteq: 0, lteq: 100) end attribute? :drone_in_dock, Types::Integer.enum(0, 1) attribute? :electric_supply_voltage, Types::Integer attribute? :flighttask_prepare_capacity, Types::Integer attribute? :flighttask_step_code, Types::Integer attribute? :job_number, Types::Integer attribute? :latitude, Types::Latitude attribute? :longitude, Types::Longitude attribute? :maintain_status do attribute :maintain_status_array, Types::Array do # {"0":"No maintenance","1":"Under maintenance"} attribute :state, Types::Integer # {"0":"No maintenance","1":"Drone basic maintenance","2":"Drone routine maintenance","3":"Drone deep maintenance","17":"Dock maintenance"} attribute :last_maintain_type, Types::Integer attribute :last_maintain_time, Types::Integer attribute :last_maintain_work_sorties, Types::Integer end end attribute? :media_file_detail do attribute :remain_upload, Types::Integer end attribute? :network_state do attribute :type, Types::Integer.enum( NETWORK_TYPE_4G = 1, NETWORK_TYPE_ETHERNET = 2 ) attribute :quality, Types::Integer.enum( QUALITY_BAD = 0, QUALITY_MODERATE = 1, QUALITY_GOOD = 2 ) attribute :rate, Types::JSON::Decimal def humanized_type type_key = case type when NETWORK_TYPE_4G "4G" when NETWORK_TYPE_ETHERNET "Ethernet" end I18n.t(type_key.downcase, scope: "dji_mqtt_connect.dock_network_state.type", default: type_key) end def humanized_quality quality_key = case quality when QUALITY_BAD "Bad" when QUALITY_MODERATE "Moderate" when QUALITY_GOOD "Good" end I18n.t(quality_key.downcase, scope: "dji_mqtt_connect.dock_network_state.quality", default: quality_key) end end attribute? :sdr do attribute :down_quality, Types::Integer attribute :frequency_band, Types::JSON::Decimal attribute :up_quality, Types::Integer end attribute? :wireless_link do attribute :_4g_freq_band, Types::JSON::Decimal attribute :_4g_gnd_quality, Types::Integer attribute :_4g_link_state, Types::Integer attribute :_4g_quality, Types::Integer attribute :_4g_uav_quality, Types::Integer attribute :dongle_number, Types::Integer attribute :link_workmode, Types::Integer attribute :sdr_freq_band, Types::JSON::Decimal attribute :sdr_link_state, Types::Integer attribute :sdr_quality, Types::Integer end attribute? :working_current, Types::Integer attribute? :working_voltage, Types::Integer # Weather attribute? :height, Types::JSON::Decimal attribute? :humidity, Types::Integer attribute? :temperature, Types::Temperature attribute? :wind_speed, Types::JSON::Decimal attribute? :environment_temperature, Types::Temperature # {"0":"No rain","1":"Light rain","2":"Moderate rain","3":"Heavy rain"} attribute? :rainfall, Types::Integer.enum( RAINFALL_NONE = 0, RAINFALL_LIGHT = 1, RAINFALL_MODERATE = 2, RAINFALL_HEAVY = 3 ) def humanized_rainfall return unless rainfall rainfall_key = case rainfall when RAINFALL_NONE "None" when RAINFALL_LIGHT "Light" when RAINFALL_MODERATE "Moderate" when RAINFALL_HEAVY "Heavy" end I18n.t(rainfall_key.downcase, scope: "dji_mqtt_connect.rainfall", default: rainfall_key) end attribute? :alternate_land_point do attribute :latitude, Types::Latitude attribute :longitude, Types::Longitude attribute :height, Types::JSON::Decimal attribute :safe_land_height, Types::JSON::Decimal attribute :is_configured, Types::Integer.enum(0, 1) end attribute? :first_power_on, Types::Integer attribute? :position_state do # {"0":"Not calibrated","1":"Calibrated"} attribute :is_calibration, Types::Integer.enum(0, 1) # {"0":"Not start","1":"fixing","2":"fix successfully","3":"fix failed"} attribute :is_fixed, Types::Integer.enum(0, 1, 2, 3) attribute :quality, Types::Integer.constrained(gteq: 0, lteq: 5) attribute :gps_number, Types::Integer attribute :rtk_number, Types::Integer end attribute? :storage do attribute :total, Types::Integer attribute :used, Types::Integer end # {"0":"Idle","1":"On-site debugging","2":"Remote debugging","3":"Firmware upgrading","4":"Working"} attribute? :mode_code, Types::Integer.enum(0, 1, 2, 3, 4) attribute? :air_conditioner do attribute :air_conditioner_state, AirConditionerState | Types::Integer attribute :switch_time, Types::Integer def air_conditioner_state? AirConditionerState.valid?(air_conditioner_state) end end # {"0":"Closed","1":"Opened"} attribute? :alarm_state, Types::Integer.enum( ALARM_STATE_CLOSED = 0, ALARM_STATE_OPEN = 1 ) def humanized_alarm_state return unless alarm_state state_key = case alarm_state when ALARM_STATE_CLOSED "Closed" when ALARM_STATE_OPEN "Open" end I18n.t(state_key.downcase, scope: "dji_mqtt_connect.dock_alarm_state", default: state_key) end # {"1":"Planned storage strategy of battery","2":"Emergency storage strategy of battery"} attribute? :battery_store_mode, Types::Integer.enum(1, 2) # {"0":"Closed","1":"Opened","2":"Half-open","3":"Cover state is abnormal"} attribute? :cover_state, Types::Integer.enum( COVER_STATE_CLOSED = 0, COVER_STATE_OPEN = 1, COVER_STATE_HALF_OPEN = 2, COVER_STATE_ABNORMAL = 3 ) def humanized_cover_state return unless cover_state state_key = case cover_state when COVER_STATE_CLOSED "Closed" when COVER_STATE_OPEN "Open" when COVER_STATE_HALF_OPEN "Half-open" when COVER_STATE_ABNORMAL "Abnormal" end I18n.t(state_key.parameterize.underscore, scope: "dji_mqtt_connect.dock_cover_state", default: state_key) end # {"0":"Closed","1":"Opened"} attribute? :emergency_stop_state, Types::Integer.enum( EMERGENCY_STOP_STATE_CLOSED = 0, EMERGENCY_STOP_STATE_OPEN = 1 ) def humanized_emergency_stop_state return unless emergency_stop_state state_key = case emergency_stop_state when EMERGENCY_STOP_STATE_CLOSED "Closed" when EMERGENCY_STOP_STATE_OPEN "Open" end I18n.t(state_key.downcase, scope: "dji_mqtt_connect.dock_emergency_stop_state", default: state_key) end # {"0":"Closed","1":"Opened","2":"Half-open","3":"Putter state is abnormal"} attribute? :putter_state, Types::Integer.enum( PUTTER_STATE_CLOSED = 0, PUTTER_STATE_OPEN = 1, PUTTER_STATE_HALF_OPEN = 2, PUTTER_STATE_ABNORMAL = 3 ) def humanized_putter_state return unless putter_state state_key = case putter_state when PUTTER_STATE_CLOSED "Closed" when PUTTER_STATE_OPEN "Open" when PUTTER_STATE_HALF_OPEN "Half-open" when PUTTER_STATE_ABNORMAL "Abnormal" end I18n.t(state_key.parameterize.underscore, scope: "dji_mqtt_connect.dock_putter_state", default: state_key) end # {"0":"Closed","1":"Opened"} attribute? :supplement_light_state, Types::Integer.enum( SUPPLEMENT_LIGHT_STATE_CLOSED = 0, SUPPLEMENT_LIGHT_STATE_OPEN = 1 ) def humanized_supplement_light_state return unless supplement_light_state state_key = case supplement_light_state when SUPPLEMENT_LIGHT_STATE_CLOSED "Closed" when SUPPLEMENT_LIGHT_STATE_OPEN "Open" end I18n.t(state_key.downcase, scope: "dji_mqtt_connect.dock_supplement_light_state", default: state_key) end attribute? :sub_device do attribute? :device_sn, Types::SerialNumber attribute? :device_model_key, Types::String # {"0":"Offline","1":"Online"} attribute :device_online_status, Types::Integer.enum(0, 1) # {"0":"Not paired","1":"Paired"} attribute :device_paired, Types::Integer.enum(0, 1) end def drone_in_dock? drone_in_dock == 1 end def environment_temperature? environment_temperature && !Types::InvalidTemperature.valid?(environment_temperature) end end def humanized_summary Translations.thing_product_dock_osd_summary(**humanized_summary_interpolation) end end end end