rdkcentral / python_raft

RAFT is a Python based testing framework for writing engineering tests. It provides a modular, config driven, low level testing framework
Apache License 2.0
3 stars 2 forks source link

Audit: Review rcCodes.py & sendKey #122

Open Ulrond opened 3 days ago

Ulrond commented 3 days ago

Goal:

sendKey(self, keycode:dict, delay:int=1, repeat:int=1, randomRepeat:int=0)

needs to be clear on the types it requires it's not a dictionary it's an enum from rcCodes.py

sendKey(self, keycode:rcCodes, delay:int=1, repeat:int=1, randomRepeat:int=0)

There are some odd codes in there which are likely removable, unless they're supported by the remote they shouldn't be present.

This would imply that the rc Module was being used for things that it shouldn't be used for, and therefore these are out of scope for usage.

    RESERVE1 = "RESERVE1"
    DCR = "DCR"
    WIFI_SSID = "WIFI_SSID"
    BLK = "BLK"
    WP = "WP"
    LIGHT_SENSOR = "LIGHT_SENSOR"
    USB = "USB"
    RJ45 = "RJ45"
    RS232 = "RS232"
    RESERVE2 = "RESERVE2"

https://github.com/rdkcentral/python_raft/blob/master/framework/core/rcCodes.py

Upgrade rcCode to have a validation function

Upgrading rcCodes to have a validation function something akin to this seems sensible.

from enum import Enum

class rcCode(Enum):
  SUCCESS = "0"
  FILE_NOT_FOUND = "1"
  # ... other codes

def validate_message_code(code_str):
  try:
    rcCode(code_str)  # Try converting to enum
    return True
  except ValueError:
    return False
Ulrond commented 3 days ago

Proposed map-table for keySimulator is an example of something new being added, but not populating the rcCodespy

remoteMaps:
  - name: "keysimulator"
    prefix: "keySimulator -k"
    codes:
### These codes need to be rcCodes.py enum list, being translated to what is required by the keySimulator app
      POWER: "power"
      HOME: "home"
      GUIDE: "guide"
      SKY: "sky"
      NUM_0: "0"
      NUM_1: "1"
      NUM_2: "2"
      NUM_3: "3"
      NUM_4: "4"
      NUM_5: "5"
      NUM_6: "6"
      NUM_7: "7"
      NUM_8: "8"
      NUM_9: "9"
      CHANNEL_UP: "chup"
      CHANNEL_DOWN: "chdown"
      UP: "up"
      DOWN: "down"
      LEFT: "left"
      RIGHT: "right"
      SELECT: "enter"
      MUTE: "mute"
      VOL_UP: "volup"
      VOL_DOWN: "voldown"
      PLAY: "play"
      PAUSE: "pause"
      FFORWARD: "fastfwd"
      REWIND: "rewind"
      RECORD: "record"
      RED: "red"
      GREEN: "green"
      YELLOW: "yellow"
      BLUE: "blue"
      PAGEUP: "pageup"
      PAGEDOWN: "pagedown"
      EXIT: "exit"
      SEARCH: "search"
      INFO: "info"
      APPS: "apps"
      ONDEMAND: "ondemand"
      HELP: "help"
      INPUTKEY: "inputkey"
      LOWBAT: "lowBat"