Skip to content

Commit 23dc326

Browse files
committed
Remove missing 1-wire devices.
1 parent ba967c3 commit 23dc326

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

myDevices/devices/manager.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
mutex = RLock()
1818

19+
def missingOneWireDevice(device):
20+
if device['class'] in FAMILIES.values() and ('slave' not in device['args'] or not deviceExists(device['args']['slave'])):
21+
logger.info('1-wire device does not exist: {}, {}'.format(device['class'], device['args']['slave']))
22+
return True
23+
return False
24+
1925
def deviceDetector():
2026
logger.debug('deviceDetector')
2127
try:
@@ -30,6 +36,9 @@ def deviceDetector():
3036
if not found:
3137
if addDevice(dev['name'], dev['device'], dev['description'], dev['args'], "auto") > 0:
3238
saveDevice(dev['name'], int(time()))
39+
missing = [key for key, value in DEVICES.items() if missingOneWireDevice(value)]
40+
for dev in missing:
41+
removeDevice(dev)
3342
except Exception as e:
3443
logger.error("Device detector: %s" % e)
3544

@@ -68,7 +77,7 @@ def removeDevice(name):
6877
if name in DEVICES:
6978
if name in DYNAMIC_DEVICES:
7079
if hasattr(DEVICES[name]["device"], 'close'):
71-
DEVICES[name]["device"].close()
80+
DEVICES[name]["device"].close()
7281
del DEVICES[name]
7382
del DYNAMIC_DEVICES[name]
7483
json_devices = getJSON(DYNAMIC_DEVICES)
@@ -135,8 +144,7 @@ def addDevice(name, device, description, args, origin):
135144
logger.error("Device <%s> already exists" % name)
136145
return -1
137146
logger.debug('addDevice: ' + str(name) + ' ' + str(device))
138-
if device in FAMILIES.values() and ('slave' not in args or not deviceExists(args['slave'])):
139-
logger.info('1-wire device does not exist: {}, {}'.format(device, args['slave']))
147+
if missingOneWireDevice({'class': device, 'args': args}):
140148
return -1
141149
# if '/' in device:
142150
# deviceClass = device.split('/')[0]

0 commit comments

Comments
 (0)