Sha256: 911f4a4538ea76370c12dd12f43a66a8cf38501b5f95a8351004dce5da78c8f5

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

module Appium
  module Core
    module Android
      module Uiautomator2
        module Device
          extend Forwardable

          # @since 1.6.0
          # @!method battery_info
          #
          # Get battery information.
          #
          # @return [Hash]  Return battery level and battery state.
          #                 Battery level in range [0.0, 1.0], where 1.0 means 100% charge. -1 is returned
          #                 if the actual value cannot be retrieved from the system.
          #                 Battery state. The following symbols are possible
          #                 `:unknown, :charging, :discharging, :not_charging, :full`
          #
          # @example
          #
          #   @driver.battery_info #=> { state: :charging, level: 0.7 }
          #

          ####
          ## class << self
          ####

          class << self
            def extended(_mod)
              ::Appium::Core::Device.add_endpoint_method(:battery_info) do
                def battery_info
                  response = execute_script 'mobile: batteryInfo', {}

                  state = case response['state']
                          when 2, 3, 4, 5
                            ::Appium::Core::Device::BatteryStatus::ANDROID[response['state']]
                          else
                            Appium::Logger.warn("The state is unknown or undefined: #{response['state']}")
                            ::Appium::Core::Device::BatteryStatus::ANDROID[1] # :unknown
                          end
                  { state: state, level: response['level'] }
                end
              end
            end
          end # class << self
        end # module Device
      end # module Uiautomator2
    end # module Android
  end # module Core
end # module Appium

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appium_lib_core-1.6.0 lib/appium_lib_core/android/uiautomator2/device.rb