Skip to content

Commit

Permalink
Added channel_to_valve to lvmopstools.devices.ion
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Sep 16, 2024
1 parent 316b579 commit 89c2fb8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Next version

### 🚀 New

* Added `channel_to_valve` mapping function to `lvmopstools.devices.ion`.


## 0.3.7 - September 15, 2024

### ✨ Improved
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Thermistors
^^^^^^^^^^^

.. autofunction:: lvmopstools.devices.thermistors.read_thermistors
.. autofunction:: lvmopstools.devices.thermistors.channel_to_valve

NPS
^^^
Expand Down
28 changes: 27 additions & 1 deletion src/lvmopstools/devices/thermistors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,39 @@
import asyncio
import re

from typing import Literal, overload

import asyncudp

from lvmopstools import config
from lvmopstools.retrier import Retrier


__all__ = ["read_thermistors"]
__all__ = ["read_thermistors", "channel_to_valve"]


@overload
def channel_to_valve(reverse: Literal[False] = False) -> dict[int, str]: ...


@overload
def channel_to_valve(reverse: Literal[True] = True) -> dict[str, int]: ...


def channel_to_valve(reverse: bool = False) -> dict[int, str] | dict[str, int]:
"""Returns a mapping of thermistor channels to valve names.
With ``reverse`` returns the inverse mapping, valve to device channel.
"""

valve_to_channel = config["devices.thermistors.channels"]

if reverse:
return valve_to_channel

channel_to_valve = {valve_to_channel[valve]: valve for valve in valve_to_channel}
return channel_to_valve


@Retrier(max_attempts=3, delay=1)
Expand Down

0 comments on commit 89c2fb8

Please sign in to comment.