1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import datetime 18 19from acts.controllers.fuchsia_lib.base_lib import BaseLib 20 21 22class FuchsiaBacklightLib(BaseLib): 23 def __init__(self, addr, tc, client_id): 24 self.address = addr 25 self.test_counter = tc 26 self.client_id = client_id 27 28 def getStateNormalized(self): 29 """Gets the backlight state and normalized brightness. 30 31 Returns: 32 The backlight state as a bool and the normalized brightness as a float in [0.0, 1.0], or 33 an error if the call failed. 34 """ 35 test_cmd = 'backlight_facade.GetStateNormalized' 36 test_args = {} 37 test_id = self.build_id(self.test_counter) 38 self.test_counter += 1 39 40 return self.send_command(test_id, test_cmd, test_args) 41 42 def setStateNormalized(self, backlight_on, brightness): 43 """Sets the backlight state and normalized brightness. 44 45 Args: 46 backlight_on: A bool indicating whether or not the backlight is on. 47 brightness: A float in [0.0, 1.0] representing the backlight brightness. 48 49 Returns: 50 None or an error if the call failed. 51 """ 52 test_cmd = 'backlight_facade.SetStateNormalized' 53 test_args = {'backlight_on': backlight_on, 'brightness': brightness} 54 test_id = self.build_id(self.test_counter) 55 self.test_counter += 1 56 57 return self.send_command(test_id, test_cmd, test_args) 58 59 def getNormalizedBrightnessScale(self): 60 """Gets the normalized brightness scale. 61 62 Returns: 63 The normalized brightness scale as a float in [0.0, 1.0], or an error if the call failed. 64 """ 65 test_cmd = 'backlight_facade.GetNormalizedBrightnessScale' 66 test_args = {} 67 test_id = self.build_id(self.test_counter) 68 self.test_counter += 1 69 70 return self.send_command(test_id, test_cmd, test_args) 71 72 def setNormalizedBrightnessScale(self, scale): 73 """Sets the normalized brightness scale. 74 75 Args: 76 scale: The normalized brightness scale to set as a float in [0.0, 1.0]. 77 78 Returns: 79 None or an error if the call failed. 80 """ 81 test_cmd = 'backlight_facade.SetNormalizedBrightnessScale' 82 test_args = scale 83 test_id = self.build_id(self.test_counter) 84 self.test_counter += 1 85 86 return self.send_command(test_id, test_cmd, test_args) 87