Module: Appium::Core::Android::Uiautomator2::Device::Battery

Defined in:
lib/appium_lib_core/android/uiautomator2/device/battery.rb

Class Method Summary collapse

Class Method Details

.add_methodsObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appium_lib_core/android/uiautomator2/device/battery.rb', line 21

def self.add_methods
  ::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::Base::Device::BatteryStatus::ANDROID[response['state']]
              else
                ::Appium::Logger.warn("The state is unknown or undefined: #{response['state']}")
                ::Appium::Core::Base::Device::BatteryStatus::ANDROID[1] # :unknown
              end
      { state: state, level: response['level'] }
    end
  end
end