aio_remeha_modbus.helpers package¶
Submodules¶
aio_remeha_modbus.helpers.gtw08 module¶
aio_remeha_modbus.helpers.iterators module¶
itertools method helpers.
Copyright (c) 2012 Erik Rose
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- class aio_remeha_modbus.helpers.iterators.UnmodifiableDict(data: dict[K, V])¶
Bases:
Mapping,GenericA Mapping implementation .
- classmethod create(data: dict[K, V]) Self¶
Create a read-only view of data.
Note: since data is referenced and not copied, changing it from another point of view change the backing data of the returned dict.
- Parameters:
data (dict[K, V]) – The dictionary to create a view from.
- Returns:
The new mapping.
- classmethod snapshot(data: dict[K, V]) Self¶
Take a snapshot of data and use that to create a new unmodifiable mapping.`.
- Parameters:
data (dict[K, V]) – The source dictionary.
- Returns:
The new mapping.
- aio_remeha_modbus.helpers.iterators.consecutive_groups(iterable, ordering=<function <lambda>>)¶
Yield groups of consecutive items using
itertools.groupby().Attribution: This method is copied from the [more-itertools](https://more-itertools.readthedocs.io/en/stable/_modules/more_itertools/more.html#consecutive_groups) library to prevent a new dependency just for a single method.
The ordering function determines whether two items are adjacent by returning their position.
By default, the ordering function is the identity function. This is suitable for finding runs of numbers:
>>> iterable = [1, 10, 11, 12, 20, 30, 31, 32, 33, 40] >>> for group in consecutive_groups(iterable): ... print(list(group)) [1] [10, 11, 12] [20] [30, 31, 32, 33] [40]
For finding runs of adjacent letters, try using the
index()method of a string of letters:>>> from string import ascii_lowercase >>> iterable = 'abcdfgilmnop' >>> ordering = ascii_lowercase.index >>> for group in consecutive_groups(iterable, ordering): ... print(list(group)) ['a', 'b', 'c', 'd'] ['f', 'g'] ['i'] ['l', 'm', 'n', 'o', 'p']
Each group of consecutive items is an iterator that shares it source with iterable. When an an output group is advanced, the previous group is no longer available unless its elements are copied (e.g., into a
list).>>> iterable = [1, 2, 11, 12, 21, 22] >>> saved_groups = [] >>> for group in consecutive_groups(iterable): ... saved_groups.append(list(group)) # Copy group elements >>> saved_groups [[1, 2], [11, 12], [21, 22]]
aio_remeha_modbus.helpers.modbus module¶
Modbus helper functions.
- type aio_remeha_modbus.helpers.modbus.ModbusPrimitive = int | float | str | list[bool] | list[int] | list[float]¶
- aio_remeha_modbus.helpers.modbus.bytes_from_registers(registers: list[int]) bytes¶
Return the raw bytes from the given list of registers.
- aio_remeha_modbus.helpers.modbus.from_registers(registers: list[int], destination_variable: ModbusVariableDescription) ModbusPrimitive | bytes | tuple[int, int] | None¶
Deserializes response into a value of type data_type.
- #### Scaling response values
Response values can be scaled by providing destination_variable.scale. For example, reading the manual setpoint from register 664 (parZoneRoomManualSetpoint) returns the setpoint as an integer (the value has a scale of 0.1). So a setpoint of 21.5 ‘C will be returned as 215. In that case, set scale to the corresponding 0.1 to retrieve the scaled value.
- Parameters:
registers (list[int]) – The modbus registers (2 bytes per register). The modbus protocol describes a big-endian representation of addresses and data items. Therefore, this method assumes big-endian ordering of the registers and their values.
destination_variable (ModbusVariableDescription) – A computer readable description of the variable to deserialize into.
- Returns:
The response, deserialized to the requested data type, or None if the response contains a GTW-08 null value.
- Raises:
ValueError – If the response cannot be decoded as the requested data type or if destination_variable.count does not exactly match the register count.
- aio_remeha_modbus.helpers.modbus.to_gtw08_null_value(data_type: DataType) int | bytes | None¶
Return the GTW-08 NULL variant for the given data type.
- aio_remeha_modbus.helpers.modbus.to_registers(source_variable: ModbusVariableDescription, value: ModbusPrimitive | tuple[int, int] | bytes | None) list[int]¶
Serialize value to a list of modbus register values.
- ### Notes:
The type of value is assumed to equal or be convertible to variable.data_type.
- If value == None, the appropriate GTW-08 null value is returned if the GTW-08 parameter list specifies it.
If no null-value is defined for variable.data_type, None is returned.
- If value is a tuple, the whole tuple must fit in a single register, contain exactly two elements that both have a
value that fits in a single byte. Therefore the individual values cannot exceed 2^8.
- Parameters:
source_variable (ModbusVariableDescription) – The description of the variable to serialize.
value (str|float|bool|tuple[int,int]|bytes|None))]) – The value to serialize.
- Returns:
The list of modbus register values. list[0] corresponds to variable.start_address.
- Return type:
list[int]
- Raises:
ValueError –
If no conversion path exists between variable.data_type and value * If conversion to a numeric type fails. * If value is a tuple which does not contain exactly two elements.
aio_remeha_modbus.helpers.validation module¶
Validation helper functions.
- aio_remeha_modbus.helpers.validation.require_not_none(value: T, message: str = 'Require a value, but got None', *args) T¶
Require a value to be not None.
- Parameters:
value (T) – The value to test.
message – str: A percent-format string containing the message.
*args – Any
- Raises:
ValueError if the value is None. –
Module contents¶
Helpers for the Remeha Modbus API.