Skip to content

Commit

Permalink
Restored the getstate method on device.py. Requested in #86
Browse files Browse the repository at this point in the history
  • Loading branch information
ralequi committed Apr 19, 2024
1 parent ab9a11f commit a981bff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Version 1.3.1
=============
- Added support for test polling_minutes. Requested in [#77](https://github.com/truenas/py-SMART/issues/77) and [#78](https://github.com/truenas/py-SMART/pull/78). Thanks @Gigahawk
- Minnor typo fixed in NvmeAttributes (issue [#81](https://github.com/truenas/py-SMART/issues/81)). Thanks @petersulyok
- Minnor typo fixed in NvmeAttributes (issue [#81](https://github.com/truenas/py-SMART/issues/81)). Thanks @petersulyok
- Fixed __getstate__ method in Device class. (issue [#86](https://github.com/truenas/py-SMART/issues/86)). Thanks @f18m
- **Breaking changes**
- **smartctl.all**:
- Officially removed support for python 3.7.
Expand Down
31 changes: 14 additions & 17 deletions pySMART/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,36 +481,33 @@ def __repr__(self):
self.serial
)

def __getstate__(self, all_info=True):
def __getstate__(self, all_info=True) -> Dict:
"""
Allows us to send a pySMART Device object over a serializable
medium which uses json (or the likes of json) payloads
"""
return None

state_dict = {
'attributes': [attr.__getstate__() if attr else None for attr in self.attributes],
'capacity': self._capacity_human,
'diagnostics': self.diagnostics.__getstate__(all_info),
'firmware': self.firmware,
'if_attributes': self.if_attributes.__getstate__() if self.if_attributes else None,
'interface': self._interface if self._interface else 'UNKNOWN INTERFACE',
'is_ssd': self.is_ssd,
'messages': self.messages,
'model': self.model,
'firmware': self.firmware,
'name': self.name,
'path': self.dev_reference,
'rotation_rate': self.rotation_rate,
'serial': self.serial,
'smart_capable': self.smart_capable,
'smart_enabled': self.smart_enabled,
'smart_status': self.assessment,
'messages': self.messages,
'temperature': self.temperature,
'test_capabilities': self.test_capabilities.copy(),
'tests': [t.__getstate__() for t in self.tests] if self.tests else [],
'diagnostics': self.diagnostics.__getstate__(all_info),
'temperature': self.temperature,
'attributes': [attr.__getstate__() if attr else None for attr in self.attributes],
'if_attributes': self.if_attributes.__getstate__(all_info) if self.if_attributes else None,
}
if all_info:
state_dict.update({
'name': self.name,
'path': self.dev_reference,
'serial': self.serial,
'is_ssd': self.is_ssd,
'rotation_rate': self.rotation_rate,
'capacity': self._capacity_human
})
return state_dict

def __setstate__(self, state):
Expand Down
2 changes: 1 addition & 1 deletion pySMART/interface/ata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse(self, data: Iterator[str]) -> None:
self.legacyAttributes[int(tmp['id'])] = Attribute(
int(tmp['id']), tmp['name'], int(tmp['flag'], base=16), tmp['value'], tmp['worst'], tmp['thresh'], tmp['type'], tmp['updated'], tmp['whenfailed'], tmp['raw'])

def __getstate__(self, all_info=True):
def __getstate__(self):
"""
Allows us to send a pySMART diagnostics object over a serializable
medium which uses json (or the likes of json) payloads
Expand Down

0 comments on commit a981bff

Please sign in to comment.