Skip to content

Add default value to nislsc python api - #67

Open
zoechanzy wants to merge 19 commits into
mainfrom
users/zchan/nislsc_default_value
Open

Add default value to nislsc python api#67
zoechanzy wants to merge 19 commits into
mainfrom
users/zchan/nislsc_default_value

Conversation

@zoechanzy

@zoechanzy zoechanzy commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

What does this Pull Request accomplish?

  • Update nislscapi_full.json
  • Update function_helper.py and templates files to consume default value from nislscapi_full.json
  • Added default value of None for the library parameter
  • Regenerate generated python modules files
  • Refactor parameter ordering in unit tests and examples

Why should this Pull Request be merged?

nislscapi.json is updated to have default values. Function helper and template files should be updated so that the default value can be used in code-gen.

What testing has been done?

  • Passed unit tests
  • Passed examples:
    -- Result of poetry run .\examples\show_command_and_property_tree.py SLSC-12001-0368CF24
{
   "Name": "SLSC-12001-0368CF24",
   "Commands": [],
   "Properties": [
       {
           "name": "PowerOnHours",
           "current_value": 1014,
           "datatype": "INT32",
           "range": "[0, ]",
           "access": "READ_WRITE",
           "description": "Recorded power-on hours of the chassis since last reset of this property. This property is persistent across reboots and factory resets.",
           "documentation": ""
       },
       {
           "name": "SupportedSlotCoolingCapacities",
           "current_value": [
               50
           ],
           "datatype": "INT32_ARRAY",
           "range": "",
           "access": "READ_ONLY",
           "description": "The cooling capacities supported by the chassis. The cooling capacity is used to determine the fan curve for the chassis. The first value listed is the default cooling capacity.",
           "documentation": ""
       },
       {
           "name": "CurrentSlotCoolingCapacity",
           "current_value": 50,
           "datatype": "INT32",
           "range": "",
           "access": "READ_WRITE",
           "description": "The current cooling capacity of the chassis. The cooling capacity is used to determine the fan curve for the chassis.",
           "documentation": ""
       },
       {
           "name": "SupportsProtectiveEarthing",
           "current_value": false,
           "datatype": "BOOL",
           "range": "",
           "access": "READ_ONLY",
           "description": "Describes whether or not this chassis supports Protective Earthing.",
           "documentation": ""
       }
   ],
   "SLSC-12001-0368CF24/BatteryVoltageSensor": {
       "Commands": [],
       "Properties": [
           {
               "name": "SensorReading",
               "current_value": 3.664550778248,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The current voltage of the battery in unit voltage.",
               "documentation": ""
           },
           {
               "name": "SensorNominal",
               "current_value": 3.6,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The nominal voltage of the battery in unit voltage.",
               "documentation": ""
           },
           {
               "name": "SensorLowerCritical",
               "current_value": 2.9,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The lower battery threshold in unit voltage.",
               "documentation": ""
           },
           {
               "name": "HealthState",
               "current_value": 0,
               "datatype": "INT32",
               "range": "",
               "access": "READ_ONLY",
               "description": "Health State of the chassis battery",
               "documentation": ""
           }
       ]
   },
   "SLSC-12001-0368CF24/FanVoltageSensor": {
       "Commands": [],
       "Properties": [
           {
               "name": "SensorReading",
               "current_value": 0.105590820226,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The current voltage of the fan in unit voltage.",
               "documentation": ""
           },
           {
               "name": "SensorLowerCritical",
               "current_value": 0.094,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The fan's lower threshold of the operating voltage in unit voltage.",
               "documentation": ""
           },
           {
               "name": "SensorUpperCritical",
               "current_value": 0.12,
               "datatype": "DOUBLE",
               "range": "",
               "access": "READ_ONLY",
               "description": "The fan's upper threshold of the operating voltage in unit voltage.",
               "documentation": ""
           },
           {
               "name": "HealthState",
               "current_value": 0,
               "datatype": "INT32",
               "range": "",
               "access": "READ_ONLY",
               "description": "Health State of the chassis fan.",
               "documentation": ""
           }
       ]
   }
}

-- Result of poetry run .\examples\reset_device.py SLSC-12001-0368CF24

Battery health state: Normal
Sensor reading: 3.664550778248 V
Battery needs replacement?: False

-- Result of poetry run .\examples\check_chassis_battery.py SLSC-12001-0368CF24

Reset command sent to device(s) SLSC-12001-0368CF24

Related work item:
USER STORY 3221873

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Update function_helpers.py and templates files to consume default value field from nislscapi_full.json
* Refactor the order of parameters to avoid python TypeError: positional argument follows keyword argument error
* Regenerate generated Python module files

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@ni-github-admins

ni-github-admins commented Aug 6, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Test Results

   14 files  ±0     14 suites  ±0   14m 47s ⏱️ -49s
  224 tests ±0    224 ✅ ±0  0 💤 ±0  0 ❌ ±0 
3 136 runs  ±0  3 136 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit abc88dd. ± Comparison against base commit 940ed0b.

♻️ This comment has been updated with latest results.

@zoechanzy
zoechanzy force-pushed the users/zchan/nislsc_default_value branch 3 times, most recently from af3371e to 6bb49f5 Compare August 6, 2026 05:54
* Added default value of None for the library parameter
* Regenerate generated Python module files

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@zoechanzy
zoechanzy force-pushed the users/zchan/nislsc_default_value branch from 6bb49f5 to 646ecac Compare August 6, 2026 06:11
@zoechanzy zoechanzy changed the title Users/zchan/nislsc default value Add default value to nislsc python api Aug 7, 2026
* Refactor parameter ordering in unit tests

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@zoechanzy
zoechanzy force-pushed the users/zchan/nislsc_default_value branch from 851de41 to fdd3ed9 Compare August 7, 2026 03:12
@zoechanzy
zoechanzy requested a lite review from Copilot August 7, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the codegen metadata and templates so generated NI-SLSC Python APIs can expose parameter default values (notably library=None, timeouts, and “default resource” sentinels), and regenerates the affected modules and tests accordingly.

Changes:

  • Added default fields to nislscapi_full.json for various parameters (timeouts, default resources).
  • Updated codegen helpers/templates to emit defaults in generated Python signatures (and to reorder required vs defaulted parameters).
  • Regenerated generated/nislsc/session.py and updated unit tests/examples to match the new call signatures.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/test_session.py Updates test calls to match reordered/generated Session method signatures and new keyword usage.
tests/unit/conftest.py Updates the session fixture to use new initialize_session_with_devices signature/keywords.
src/codegen/utilities/function_helpers.py Adds “include defaults” support, default formatting helpers, and signature reordering logic.
src/codegen/templates/utils.py.mako Enables default emission for module-level generated functions.
src/codegen/templates/session.py.mako Enables default emission for generated Session methods/classmethods.
src/codegen/templates/property.py.mako Enables default emission for generated PropertyReference APIs.
src/codegen/templates/library.py.mako Enables default emission for generated Library APIs.
src/codegen/templates/command.py.mako Enables default emission for generated CommandReference APIs.
src/codegen/metadata/nislscapi_full.json Adds default values in metadata (timeouts, $Default* resource sentinels).
generated/nislsc/session.py Regenerated Session API with defaults and reordered parameters.
examples/show_command_and_property_tree.py Updates example calls to match new Session method parameter order.
examples/reset_device.py Updates example initialization call to use new keyword/default patterns.
examples/check_chassis_battery.py Updates example property calls to match new parameter ordering/defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/codegen/utilities/function_helpers.py
Comment thread src/codegen/utilities/function_helpers.py
@zoechanzy
zoechanzy marked this pull request as ready for review August 7, 2026 05:36
Comment thread examples/show_command_and_property_tree.py Outdated
Comment thread examples/show_command_and_property_tree.py Outdated
Comment thread examples/show_command_and_property_tree.py Outdated
@tjying95

tjying95 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Perform the tests on actual hardware and make sure the examples still work. Also try writing a simple python script to test if the default parameter is working as intended, especially the $DefaultDevices and $DefaultPhysChans.

@tjying95
tjying95 requested a review from junliang-tan August 11, 2026 06:01
* Refactor parameter ordering in examples to match new defaults
* Remove library,connection_timeout and reservation_timeout parameters from examples since they have default values.
---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
…types

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@zoechanzy
zoechanzy force-pushed the users/zchan/nislsc_default_value branch from 0bf3a56 to 30845a7 Compare August 11, 2026 08:09
Comment thread generated/nislsc/session.py Outdated
Comment thread generated/nislsc/session.py Outdated
Comment thread examples/show_command_and_property_tree.py Outdated
Comment thread src/codegen/templates/command.py.mako Outdated
Comment thread src/codegen/utilities/function_helpers.py
Comment thread tests/unit/conftest.py Outdated
Comment thread tests/unit/test_session.py Outdated
Comment thread tests/unit/test_session.py Outdated
Comment thread examples/check_chassis_battery.py
* Add * in get_function_parameter_list to make the Booleans keyword-only
* Remove argument from get_function_parameter_list if the argument have default value.
* Use named parameters for get_function_parameter_list to avoid ambiguity
* Add CONNECTED_DEVICES_ALIAS constant
* Add RESERVED_DEVICES_ALIAS constant
* Add DEFAULT_NVMEM_AREAS_ALIAS constant
* Add DEFAULT_PHYS_CHANS_ALIAS constant
* Add RESERVED_DEVICES_ALIAS constant
* Add SESSION_ALIAS constant
* Add SYSTEM_ALIAS constant

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Change timeout default value from -1 to -1.0
* Add default value "" for reservationGroup
* Add default value "read/write" for reservationAccess
* Update function_helpers.py to convert read/write to READ_WRITE
* Generate new session.py with updated default values
---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@zoechanzy
zoechanzy force-pushed the users/zchan/nislsc_default_value branch from 053dc9b to 4175108 Compare August 17, 2026 07:15
* Remove parameters from intialization if its value same as default value.
* Reorder parameters to match the order in the function definition.

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Reorder parameters to match the order in the function definition.

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
@zoechanzy
zoechanzy requested a review from bkeryan August 18, 2026 01:28
* Add get_default_alias_constants in function_helpers.py to retrieve default alias constants.
* Update session.py.mako to use get_default_alias_constants for default values.
* Generate session.py with updated default values

---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Remove default value of device/physchan/nvmem from read/write register and execute device/physicalChannel command
* Generate new session.py with updated default values
---------

Signed-off-by: zoechanzy <zoe.chan@emerson.com>
Comment thread examples/check_chassis_battery.py Outdated
Comment thread examples/check_chassis_battery.py
Comment thread examples/reset_device.py Outdated
Comment thread examples/show_command_and_property_tree.py Outdated
Comment thread examples/reset_device.py Outdated
Comment thread examples/show_command_and_property_tree.py Outdated
…n with the LabVIEW example

Allow the session API to use its default reservation group when checking
chassis battery. This matches the behavior of the equivalent LabVIEW
example.

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…LT_CHANS_ALIAS to align with the LabVIEW example

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…device to align with the LabVIEW example

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…e to align with the LabVIEW example

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
@junliang-tan
junliang-tan removed their request for review August 24, 2026 17:31
…VIEW example

Remove device_names from reset_devices so that default devices are used.
This aligns with the behavior of the equivalent LabVIEW example.

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…vice alias for property queries

Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
@junliang-tan
junliang-tan force-pushed the users/zchan/nislsc_default_value branch from f6ab02e to abc88dd Compare August 24, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants