blob: abbe84bc34e13f8a26650f3a187d3c161c5e7d7b [file] [log] [blame]
James Feist57444232018-03-08 13:36:32 -08001#!/usr/bin/python
2"""
3This script sets muxes back to default values so that
4during device parsing we are not left with an invisible
5mux before the mux has been added to device tree.
6
7If we find a better way to take care of this, we should
8remove this file.
9"""
10
11import os
12import json
13import subprocess
14
15
16CONFIGURATION_FILE = '/var/configuration/system.json'
17MUX_TYPES = ['PCA9543Mux', 'PCA9545Mux']
18
19if not os.path.isfile(CONFIGURATION_FILE):
20 print('No Configuration')
21 exit(0)
22
23configuration = json.load(open(CONFIGURATION_FILE))
24
25for _, entity in configuration.iteritems():
James Feist1e3e6982018-08-03 16:09:28 -070026 for exposed in entity.get('Exposes', []):
27 if exposed.get('Type', None) in MUX_TYPES:
28 bus = exposed.get('Bus', False)
29 address = exposed.get('Address', False)
James Feist57444232018-03-08 13:36:32 -080030 if bus and address:
31 subprocess.call('i2cset -y -f {} {} 0'.format(bus, address),
32 shell=True)