Skip to content
Merged
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
3 changes: 3 additions & 0 deletions pymodbus/pdu/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def __init__(self, info=None, info_name=None):
:param info: Device information as {int:string} dictionary
:param info_name: Device information as {name:string} dictionary
"""
# Copy the defaults, so each identity has its own values instead of
# all instances writing into the class-level dict.
self.stat_data = dict(self.stat_data)
if isinstance(info_name, dict):
for key in info_name:
inx = self.__names.index(key)
Expand Down
13 changes: 13 additions & 0 deletions test/pdu/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ def test_update_identity(self):
assert self.control.Identity.ModelName == "bashwork"
assert self.control.Identity.UserApplicationName == "pytest"

def test_identities_do_not_share_data(self):
"""Test each identity keeps its own values."""
first = ModbusDeviceIdentification(info_name={"VendorName": "first"})
second = ModbusDeviceIdentification(info_name={"VendorName": "second"})
assert first.VendorName == "first"
assert second.VendorName == "second"

def test_new_identity_does_not_change_server_identity(self):
"""Test creating an identity does not alter the control block."""
self.control.Identity.update(self.ident)
ModbusDeviceIdentification(info_name={"VendorName": "other"})
assert self.control.Identity.VendorName == "Bashwork"

def test_device_identification_factory(self):
"""Test device identification reading."""
self.control.Identity.update(self.ident)
Expand Down
Loading