Skip to content

Commit 68574b2

Browse files
committed
Added scale_division parameter for conversions
1 parent 0bca78e commit 68574b2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

custom_components/solarman/parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def try_parse_signed (self, rawData, definition, start, length):
7878
value = (value - maxint) * scale
7979
else:
8080
value = value * scale
81+
82+
if ('scale_division' in definition) and (definition['scale_division'] > 0):
83+
value //= definition['scale_division']
8184

8285
if 'validation' in definition:
8386
if not self.do_validate(title, value, definition['validation']):
@@ -116,6 +119,9 @@ def try_parse_unsigned (self, rawData, definition, start, length):
116119
value = value - definition['offset']
117120

118121
value = value * scale
122+
123+
if ('scale_division' in definition) and (definition['scale_division'] > 0):
124+
value //= definition['scale_division']
119125

120126
if 'validation' in definition:
121127
if not self.do_validate(title, value, definition['validation']):

customization.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The group just groups parameters that belong together. The induvidual parameter-
7979
|icon||The *icon* field of the home-assistant entity #|
8080
|| **The fields below define how the value from the logger is parsed** |
8181
|scale||Scaling factor for the value read from the logger (default: 1)|
82+
|scale_division||If specified, divides the result of the scaling by this number (e.g. if the value of the register is in minutes and you want the home-assistant entity in hours, use `scale_division: 60` and `uom: "h"`)
8283
|rule||Method to interpret the data from the logger (see the table below)|
8384
|mask||A mask to filter only used bit fields; this is especialy useful for flag fields|
8485
|registers||Array of register fields that comprises the value; if the value is placed in a number of registers, this array will contain more than one item (note: order is important)|
@@ -122,5 +123,5 @@ The `rule` field specifies how to interpret the binary data contained in the reg
122123
| 6 | Bit field | |
123124
| 7 | Version | |
124125
| 8 | Date Time | |
125-
| 9 | Time | Time value as string<ul><li>Example 1: Register Value 2200 => Time Value: 22:00</li><li>Example 2: Register value: 400 => 04:00</li></ul>|
126+
| 9 | Time | Time value as string<ul><li>Example 1: Register Value 2200 => Time Value: 22:00</li><li>Example 2: Register value: 400 => 04:00</li></ul>|
126127

0 commit comments

Comments
 (0)