Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lewis_emulators/opcua/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ..lewis_versions import LEWIS_LATEST
from .device import SimulatedFinsPLC

framework_version = LEWIS_LATEST

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'framework_version' is not used.

Copilot Autofix

AI 5 months ago

To fix the issue, we need to either:

  1. Rename the variable to indicate that it is intentionally unused (e.g., _unused_framework_version), or
  2. Remove the assignment entirely if it is not needed.

Since there is no indication that the variable is intentionally unused or required for documentation purposes, the best approach is to remove the assignment entirely. This ensures the code remains clean and avoids confusion about the purpose of the variable.


Suggested changeset 1
lewis_emulators/opcua/__init__.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lewis_emulators/opcua/__init__.py b/lewis_emulators/opcua/__init__.py
--- a/lewis_emulators/opcua/__init__.py
+++ b/lewis_emulators/opcua/__init__.py
@@ -3,3 +3,3 @@
 
-framework_version = LEWIS_LATEST
+
 __all__ = ["SimulatedFinsPLC"]
EOF
@@ -3,3 +3,3 @@

framework_version = LEWIS_LATEST

__all__ = ["SimulatedFinsPLC"]
Copilot is powered by AI and may make mistakes. Always verify output.
__all__ = ["SimulatedFinsPLC"]
24 changes: 24 additions & 0 deletions lewis_emulators/opcua/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from collections import OrderedDict

Check failure on line 1 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (F401)

lewis_emulators/opcua/device.py:1:25: F401 `collections.OrderedDict` imported but unused

from lewis.devices import StateMachineDevice
from lewis.core.statemachine import State

Check failure on line 4 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (F401)

lewis_emulators/opcua/device.py:4:37: F401 `lewis.core.statemachine.State` imported but unused

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'State' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we will remove the unused import statement from lewis.core.statemachine import State on line 4. This will eliminate the unnecessary dependency and improve code readability. No other changes are required, as the removal of this import does not affect the functionality of the code.

Suggested changeset 1
lewis_emulators/opcua/device.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lewis_emulators/opcua/device.py b/lewis_emulators/opcua/device.py
--- a/lewis_emulators/opcua/device.py
+++ b/lewis_emulators/opcua/device.py
@@ -3,3 +3,3 @@
 from lewis.devices import StateMachineDevice
-from lewis.core.statemachine import State
+
 
EOF
@@ -3,3 +3,3 @@
from lewis.devices import StateMachineDevice
from lewis.core.statemachine import State


Copilot is powered by AI and may make mistakes. Always verify output.

from .states import DefaultState

Check failure on line 6 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (F401)

lewis_emulators/opcua/device.py:6:21: F401 `.states.DefaultState` imported but unused

Check failure on line 6 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (I001)

lewis_emulators/opcua/device.py:1:1: I001 Import block is un-sorted or un-formatted

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'DefaultState' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we will remove the unused import statement from .states import DefaultState from the file lewis_emulators/opcua/device.py. This will clean up the code and eliminate the unnecessary dependency.

Suggested changeset 1
lewis_emulators/opcua/device.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lewis_emulators/opcua/device.py b/lewis_emulators/opcua/device.py
--- a/lewis_emulators/opcua/device.py
+++ b/lewis_emulators/opcua/device.py
@@ -5,3 +5,3 @@
 
-from .states import DefaultState
+
 
EOF
@@ -5,3 +5,3 @@

from .states import DefaultState


Copilot is powered by AI and may make mistakes. Always verify output.

class SimulatedOPCUA(StateMachineDevice):
"""Class representing a simulated OPC UA PLC.
"""

#Need a dictionary ? of some sort to store PV values and their
#corresponding address/name on the OPCUA server. Also need
#IP address and other server info, and possibly library to start
#the server...

def _get_state_handlers(self):

Check failure on line 17 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN202)

lewis_emulators/opcua/device.py:17:9: ANN202 Missing return type annotation for private function `_get_state_handlers`
return super()._get_state_handlers()

def _get_initial_state(self):

Check failure on line 20 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN202)

lewis_emulators/opcua/device.py:20:9: ANN202 Missing return type annotation for private function `_get_initial_state`
return super()._get_initial_state()

def _get_transition_handlers(self):

Check failure on line 23 in lewis_emulators/opcua/device.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN202)

lewis_emulators/opcua/device.py:23:9: ANN202 Missing return type annotation for private function `_get_transition_handlers`
return super()._get_transition_handlers()
54 changes: 54 additions & 0 deletions lewis_emulators/opcua/interfaces/opcua_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from lewis.adapters import opcua

Check failure on line 1 in lewis_emulators/opcua/interfaces/opcua_interface.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (F401)

lewis_emulators/opcua/interfaces/opcua_interface.py:1:28: F401 `lewis.adapters.opcua` imported but unused

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'opcua' is not used.

Copilot Autofix

AI 5 months ago

To fix the issue, the unused import statement from lewis.adapters import opcua on line 1 should be removed. This will eliminate the unnecessary dependency and improve the clarity of the code. No other changes are required, as the removal of this import does not affect the functionality of the program.

Suggested changeset 1
lewis_emulators/opcua/interfaces/opcua_interface.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lewis_emulators/opcua/interfaces/opcua_interface.py b/lewis_emulators/opcua/interfaces/opcua_interface.py
--- a/lewis_emulators/opcua/interfaces/opcua_interface.py
+++ b/lewis_emulators/opcua/interfaces/opcua_interface.py
@@ -1,2 +1 @@
-from lewis.adapters import opcua
 
EOF
@@ -1,2 +1 @@
from lewis.adapters import opcua

Copilot is powered by AI and may make mistakes. Always verify output.

"""
This is a fake OPC UA server interface which creates three values:
a temperature float, a name string, and a status boolean.
"""

class OPCUAInterface:
"""Interface for my device."""

def __init__(self):

Check failure on line 11 in lewis_emulators/opcua/interfaces/opcua_interface.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN204)

lewis_emulators/opcua/interfaces/opcua_interface.py:11:9: ANN204 Missing return type annotation for special method `__init__`
self._temperature = 25.0
self._vacuum_status = False

@property
def temperature(self):

Check failure on line 16 in lewis_emulators/opcua/interfaces/opcua_interface.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (ANN201)

lewis_emulators/opcua/interfaces/opcua_interface.py:16:9: ANN201 Missing return type annotation for public function `temperature`
"""Current temperature (read/write)"""
return self._temperature

@temperature.setter
def set_temperature(self, value):
"""Set the temperature."""
self.temperature = float(value)

@property
def vacuum_status(self):
"""Vacuum status (read-only)"""
return self._vacuum_status

def set_vacuum(self, status: bool):
"""Simulate a change in vacuum status"""
self._vacuum_status = bool(status)

@property
def name(self):
"""Device name (read-only)"""
return "TestOPCUADevice"



def reset(self):
"""Reset the device."""
self.temperature = 25.0
self._vacuum_status = False
return True

# Configuration for the adapter
opcua_adapter = {
'options': {
'port': 4840,
'server_name': 'OPC UA Server',
'read_only_properties': ['status']
}
}
5 changes: 5 additions & 0 deletions lewis_emulators/opcua/states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lewis.core.statemachine import State


class DefaultState(State):
pass
57 changes: 57 additions & 0 deletions other_emulators/opcua/simple-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import asyncio
import logging

from asyncua import Server, ua
from asyncua.common.methods import uamethod


@uamethod
def func(parent, value):
return value * 2


async def main():
_logger = logging.getLogger(__name__)
# setup our server
server = Server()
await server.init()
server.set_endpoint("opc.tcp://0.0.0.0:4840")

# set up our own namespace, not really necessary but should as spec
uri = "http://isiscomputing-namespace.epics"
idx = await server.register_namespace(uri)

# populating our address space
# server.nodes, contains links to very common nodes like objects and root
print(type(idx), idx)
myobj = await server.nodes.objects.add_object(idx, bname="Pressure_Values")
pressure_var = await myobj.add_variable(idx, "Pressure", 6.7)
temp_var = await myobj.add_variable(idx, "Temperature", 30.5)
# Set Pressure and Temperature to be writable by clients
await pressure_var.set_writable()
await temp_var.set_writable()
await server.nodes.objects.add_method(
ua.NodeId("ServerMethod", idx),
ua.QualifiedName("ServerMethod", idx),
func,
[ua.VariantType.Int64],
[ua.VariantType.Int64],
)
_logger.info("Starting server!")

print(f"Pressure NodeId: {pressure_var.nodeid}")
print(f"Temperature NodeId: {temp_var.nodeid}")
async with server:
while True:
await asyncio.sleep(1)
new_val = await pressure_var.get_value() + 0.1
new_val2 = await temp_var.get_value() + 0.05
_logger.info("Set value of %s to %.1f", pressure_var, new_val)
_logger.info("Set value of %s to %.1f", temp_var, new_val2)
await pressure_var.write_value(new_val)
await temp_var.write_value(new_val2)


if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main(), debug=False)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lewis
asyncua
Loading