File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ Get temperature when there is only one 1-wire device on the bus::
46
46
from digitemp.master import UART_Adapter
47
47
from digitemp.device import TemperatureSensor
48
48
49
- sensor = TemperatureSensor(UART_Adapter('/dev/ttyS0')
49
+ sensor = TemperatureSensor(UART_Adapter('/dev/ttyS0'))
50
50
sensor.info()
51
51
print(sensor.get_temperature())
52
52
Original file line number Diff line number Diff line change 1
- __version__ = '1.4.0 '
1
+ __version__ = '1.4.1 '
Original file line number Diff line number Diff line change 3
3
from ..exceptions import OneWireException
4
4
from ..utils import *
5
5
6
+ if PY3 :
7
+ from typing import Optional
8
+
6
9
__temperatureSensors = {
7
10
0x10 : DS18S20 ,
8
11
0x22 : DS1822 ,
9
12
0x28 : DS18B20 ,
10
13
}
11
14
12
15
13
- def TemperatureSensor (bus , rom ):
14
- # type: (UART_Adapter, str) -> OneWireTemperatureSensor
16
+ def TemperatureSensor (bus , rom = None ):
17
+ """
18
+ If rom is not, will try to find a connected device.
19
+ In that case there must be only one device connected.
20
+ """
21
+ # type: (UART_Adapter, Optional[str]) -> OneWireTemperatureSensor
22
+ if rom is None :
23
+ roms = bus .get_connected_ROMs ()
24
+ if len (roms ) > 1 :
25
+ raise OneWireException (f"More than one connected 1-wire device found: { ', ' .join (roms )} " )
26
+ rom = roms [0 ]
15
27
family_code = iord (str2rom (rom ), 0 )
16
28
if family_code not in __temperatureSensors :
17
29
raise OneWireException ("Unsupported family code: %d" % family_code )
You can’t perform that action at this time.
0 commit comments