PyVLCB 0.2.2__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyVLCB
3
- Version: 0.2.2
3
+ Version: 0.2.7
4
4
  Summary: A library for CBUS / VLCB communication
5
5
  Author-email: "Stewart Watkiss (penguintutor)" <5587863+penguintutor@users.noreply.github.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyVLCB"
7
- version = "0.2.2"
7
+ version = "0.2.7"
8
8
  description = "A library for CBUS / VLCB communication"
9
9
  readme = {file="README.md", content-type = "text/markdown"}
10
10
  requires-python = ">=3.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyVLCB
3
- Version: 0.2.2
3
+ Version: 0.2.7
4
4
  Summary: A library for CBUS / VLCB communication
5
5
  Author-email: "Stewart Watkiss (penguintutor)" <5587863+penguintutor@users.noreply.github.com>
6
6
  License: MIT License
@@ -124,8 +124,8 @@ class VLCB:
124
124
  opcode_string = f'{opcode} - {VLCBOpcode.opcode_mnemonic(opcode)}'
125
125
  #data_string = f"{VLCBOpcode.parse_data(vlcb_entry.data)}"
126
126
  data_string = dict_to_string(VLCBOpcode.parse_data(vlcb_entry.data))
127
- return [date_string, direction, message, str(vlcb_entry.can_id), opcode_string, data_string]
128
- # Todo - error handling
127
+ description_string = vlcb_entry.get_description()
128
+ return [date_string, direction, message, str(vlcb_entry.can_id), opcode_string, data_string, description_string]
129
129
 
130
130
 
131
131
  # Static Methods moved to utils
@@ -250,9 +250,16 @@ class VLCB:
250
250
  Returns:
251
251
  String: A string for the request
252
252
  """
253
+
253
254
  # if ev_id is a string then convert to an int
254
255
  # Setting based to 0 will automatically handle base 10 or hex
255
- ev_id = int(ev_id, 0)
256
+ if not isinstance(ev_id, (int, str)):
257
+ raise TypeError(f"Expected int or str, got {type(ev_id).__name__}")
258
+
259
+ # Convert strings (ints are ignored and remain ints)
260
+ if isinstance(ev_id, str):
261
+ ev_id = int(ev_id, 0)
262
+
256
263
  # determine if long or short
257
264
  if ev_id <= 0xffff:
258
265
  return self.accessory_short_command (node_id, ev_id, state)
@@ -491,4 +498,4 @@ class VLCB:
491
498
  return f"{self.make_header(opcode='60')}60{num_to_1hexstr(session_id)}{byte1_2[0]}{byte1_2[1]};"
492
499
 
493
500
 
494
-
501
+
@@ -62,6 +62,24 @@ class VLCBFormat :
62
62
  """
63
63
  return VLCBOpcode.parse_data(self.data)
64
64
 
65
+
66
+ def get_description (self): # -> str:
67
+ """Returns a human readable string based on the data string
68
+
69
+ Returns:
70
+ String
71
+
72
+ Raises:
73
+ ValueError: If opcode not found
74
+ """
75
+ str_value = self.data[0:2]
76
+ if str_value in VLCBOpcode.opcodes.keys():
77
+ #TODO: Currently returns title - in future look to parse loco ID if appropriate
78
+ return VLCBOpcode.opcodes[str_value]['title']
79
+ else:
80
+ raise ValueError(f"Opcode {str_value} is not defined.")
81
+
82
+
65
83
  def format_data (self) -> OpcodeData:
66
84
  """Returns the opcode associated with the data string
67
85
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes