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 17from acts.controllers.fuchsia_lib.base_lib import BaseLib 18 19 20class RgbValue: 21 # use __dict__ to send in json 22 def __init__(self, r, g, b): 23 self.red = r 24 self.green = g 25 self.blue = b 26 27 28class FuchsiaLightLib(BaseLib): 29 def __init__(self, addr, tc, client_id): 30 self.address = addr 31 self.test_counter = tc 32 self.client_id = client_id 33 34 def getNumLights(self): 35 """ Gets the total number of physical lights on the Fuchsia device 36 under test. 37 38 Returns: 39 Integer (number of lights), prints an error message if error. 40 """ 41 test_cmd = "light_facade.GetNumLights" 42 test_args = {} 43 test_id = self.build_id(self.test_counter) 44 self.test_counter += 1 45 46 return self.send_command(test_id, test_cmd, test_args) 47 48 def getNumLightGroups(self): 49 """ Gets the total number of light groups on the Fuchsia device 50 under test. 51 52 Returns: 53 Integer (number of light groups), prints an error message if error. 54 """ 55 test_cmd = "light_facade.GetNumLightGroups" 56 test_args = {} 57 test_id = self.build_id(self.test_counter) 58 self.test_counter += 1 59 60 return self.send_command(test_id, test_cmd, test_args) 61 62 def getInfo(self, index): 63 """ Gets info (name and capability) for a single light on the Fuchsia device 64 under test. 65 66 Args: 67 index: uint32, index of the light defined by board, must be less than 68 value returned by getNumLights 69 70 Returns: 71 The Info object, prints an error message if error. 72 """ 73 test_cmd = "light_facade.GetInfo" 74 test_args = {"index": index} 75 test_id = self.build_id(self.test_counter) 76 self.test_counter += 1 77 78 return self.send_command(test_id, test_cmd, test_args) 79 80 def getCurrentSimpleValue(self, index): 81 """ Gets the current simple value for a single light on the Fuchsia device 82 under test. 83 84 Args: 85 index: uint32, index of the light defined by board, must be less than 86 value returned by getNumLights 87 88 Returns: 89 Boolean. True if the light is ON, False if the light is OFF. 90 If the capability 'SIMPLE' is not supported by this light, fails and prints 91 error message. 92 Use GetInfo to check if light supports this operation. 93 """ 94 test_cmd = "light_facade.GetCurrentSimpleValue" 95 test_args = {"index": index} 96 test_id = self.build_id(self.test_counter) 97 self.test_counter += 1 98 99 return self.send_command(test_id, test_cmd, test_args) 100 101 def setSimpleValue(self, index, value): 102 """ Sets the simple value for a single light on the Fuchsia device 103 under test. 104 105 Args: 106 index: uint32, index of the light defined by board, must be less than 107 value returned by getNumLights 108 value: boolean, True for ON, False for OFF 109 110 Returns: 111 None if success, prints error message if error (e.g. capability 'SIMPLE' 112 is not supported by the light). 113 """ 114 test_cmd = "light_facade.SetSimpleValue" 115 test_args = {"index": index, "value": value} 116 test_id = self.build_id(self.test_counter) 117 self.test_counter += 1 118 119 return self.send_command(test_id, test_cmd, test_args) 120 121 def getCurrentBrightnessValue(self, index): 122 """ Gets the current brightness value for a single light on the Fuchsia device 123 under test. 124 125 Args: 126 index: uint32, index of the light defined by board, must be less than 127 value returned by getNumLights 128 129 Returns: 130 uint8. A value 0-255 inclusive indicating the brightness of the light. 131 If the capability 'BRIGHTNESS' is not supported by this light, fails and prints 132 error message. 133 Use GetInfo to check if light supports this operation. 134 """ 135 test_cmd = "light_facade.GetCurrentBrightnessValue" 136 test_args = {"index": index} 137 test_id = self.build_id(self.test_counter) 138 self.test_counter += 1 139 140 return self.send_command(test_id, test_cmd, test_args) 141 142 def setBrightnessValue(self, index, value): 143 """ Sets the brightness value for a single light on the Fuchsia device 144 under test. 145 146 Args: 147 index: uint32, index of the light defined by board, must be less than 148 value returned by getNumLights 149 value: uint8, 0-255 inclusive indicating the brightness of the light 150 151 Returns: 152 None if success, prints error message if error (e.g. capability 153 'BRIGHTNESS' is not supported by the light). 154 """ 155 test_cmd = "light_facade.SetBrightnessValue" 156 test_args = {"index": index, "value": value} 157 test_id = self.build_id(self.test_counter) 158 self.test_counter += 1 159 160 return self.send_command(test_id, test_cmd, test_args) 161 162 def getCurrentRgbValue(self, index): 163 """ Gets the current RGB value for a single light on the Fuchsia device 164 under test. 165 166 Args: 167 index: uint32, index of the light defined by board, must be less than 168 value returned by getNumLights 169 170 Returns: 171 The RGB object indicating the RGB value of the light. 172 If the capability 'RGB' is not supported by this light, fails and prints 173 error message. 174 Use GetInfo to check if light supports this operation. 175 """ 176 test_cmd = "light_facade.GetCurrentRgbValue" 177 test_args = {"index": index} 178 test_id = self.build_id(self.test_counter) 179 self.test_counter += 1 180 181 return self.send_command(test_id, test_cmd, test_args) 182 183 def setRgbValue(self, index, value): 184 """ Sets the RGB value for a single light on the Fuchsia device 185 under test. 186 187 Args: 188 index: uint32, index of the light defined by board, must be less than 189 value returned by getNumLights 190 value: an RGB object 191 192 Returns: 193 None if success, prints error message if error (e.g. capability 'RGB' 194 is not supported by the light). 195 """ 196 test_cmd = "light_facade.SetRgbValue" 197 test_args = {"index": index, "value": value} 198 test_id = self.build_id(self.test_counter) 199 self.test_counter += 1 200 201 return self.send_command(test_id, test_cmd, test_args) 202 203 def getGroupInfo(self, index): 204 """ Gets group info (name, number of lights, and capability) for a light 205 group on the Fuchsia device under test. 206 207 Args: 208 index: uint32, index of the light group defined by board, must be less 209 than value returned by getNumLightGroups 210 211 Returns: 212 The GroupInfo object, prints an error message if error. 213 """ 214 test_cmd = "light_facade.GetGroupInfo" 215 test_args = {"index": index} 216 test_id = self.build_id(self.test_counter) 217 self.test_counter += 1 218 219 return self.send_command(test_id, test_cmd, test_args) 220 221 def getGroupCurrentSimpleValue(self, index): 222 """ Gets the current simple values for the light group on the Fuchsia device 223 under test. 224 225 Args: 226 index: uint32, index of the light group defined by board, must be less than 227 value returned by getNumLightGroups 228 229 Returns: 230 Vector of booleans, each indicating whether or not the light is on. 231 If the capability 'SIMPLE' is not supported by the light group, fails and prints 232 error message. 233 Use GetGroupInfo to check if light supports this operation. 234 """ 235 test_cmd = "light_facade.GetGroupCurrentSimpleValue" 236 test_args = {"index": index} 237 test_id = self.build_id(self.test_counter) 238 self.test_counter += 1 239 240 return self.send_command(test_id, test_cmd, test_args) 241 242 def setGroupSimpleValue(self, index, values): 243 """ Sets the simple value for a light group on the Fuchsia device 244 under test. 245 246 Args: 247 index: uint32, index of the light defined by board, must be less than 248 value returned by getNumLights 249 values: a vector of booleans, each has True for ON, False for OFF 250 251 Returns: 252 None if success, prints error message if error (e.g. capability 'SIMPLE' 253 is not supported by the light group). 254 """ 255 test_cmd = "light_facade.SetGroupSimpleValue" 256 test_args = {"index": index, "values": values} 257 test_id = self.build_id(self.test_counter) 258 self.test_counter += 1 259 260 return self.send_command(test_id, test_cmd, test_args) 261 262 def getGroupCurrentBrightnessValue(self, index): 263 """ Gets the current brightness values for the light group on the Fuchsia device 264 under test. 265 266 Args: 267 index: uint32, index of the light group defined by board, must be less than 268 value returned by getNumLightGroups 269 270 Returns: 271 Vector of uint8, each indicating the brightness of the light. 272 If the capability 'SIMPLE' is not supported by the light group, fails and prints 273 error message. 274 Use GetGroupInfo to check if light supports this operation. 275 """ 276 test_cmd = "light_facade.GetGroupCurrentBrightnessValue" 277 test_args = {"index": index} 278 test_id = self.build_id(self.test_counter) 279 self.test_counter += 1 280 281 return self.send_command(test_id, test_cmd, test_args) 282 283 def setGroupBrightnessValue(self, index, values): 284 """ Sets the brightness value for a light group on the Fuchsia device 285 under test. 286 287 Args: 288 index: uint32, index of the light defined by board, must be less than 289 value returned by getNumLights 290 values: a vector of uint8s, each indicating the brightness of a light. 291 292 Returns: 293 None if success, prints error message if error (e.g. capability 'BRIGHTNESS' 294 is not supported by the light group). 295 """ 296 test_cmd = "light_facade.SetGroupBrightnessValue" 297 test_args = {"index": index, "values": values} 298 test_id = self.build_id(self.test_counter) 299 self.test_counter += 1 300 301 return self.send_command(test_id, test_cmd, test_args) 302 303 def getGroupCurrentRgbValue(self, index): 304 """ Gets the current RGB values for the light group on the Fuchsia device 305 under test. 306 307 Args: 308 index: uint32, index of the light group defined by board, must be less than 309 value returned by getNumLightGroups 310 311 Returns: 312 Vector of RGB objects, each indicating the RGB value of the light. 313 If the capability 'RGB' is not supported by the light group, fails and prints 314 error message. 315 Use GetGroupInfo to check if light supports this operation. 316 """ 317 test_cmd = "light_facade.GetGroupCurrentRgbValue" 318 test_args = {"index": index} 319 test_id = self.build_id(self.test_counter) 320 self.test_counter += 1 321 322 return self.send_command(test_id, test_cmd, test_args) 323 324 def setGroupRgbValue(self, index, values): 325 """ Sets the RGB value for a light group on the Fuchsia device 326 under test. 327 328 Args: 329 index: uint32, index of the light defined by board, must be less than 330 value returned by getNumLights 331 values: a vector of RGB objects, each indicating the RGB value of a light. 332 333 Returns: 334 None if success, prints error message if error (e.g. capability 'RGB' 335 is not supported by the light group). 336 """ 337 test_cmd = "light_facade.SetGroupRgbValue" 338 test_args = {"index": index, "values": values} 339 test_id = self.build_id(self.test_counter) 340 self.test_counter += 1 341 342 return self.send_command(test_id, test_cmd, test_args) 343