add new hwmon dbus obj
diff --git a/bin/Barreleye.py b/bin/Barreleye.py
index 6e213a5..bd0b096 100755
--- a/bin/Barreleye.py
+++ b/bin/Barreleye.py
@@ -21,7 +21,7 @@
 	'HOST_POWERED_ON',
 	'HOST_BOOTING',
 	'HOST_BOOTED',
-	'HOST_POWERED_DOWN',
+	'HOST_POWERED_OFF',
 ]
 
 EXIT_STATE_DEPEND = {
@@ -172,11 +172,12 @@
 		'process_name'    : 'phosphor-read-eeprom',
 		'args'            : ['--eeprom','/sys/devices/platform/ahb/ahb:apb/1e78a000.i2c/1e78a040.i2c-bus/i2c-0/0-0050/eeprom','--fruid','64'],
 	},
-	'hwmon_barreleye' : {
+	'hwmon' : {
 		'system_state'    : 'BMC_STARTING',
 		'start_process'   : True,
 		'monitor_process' : True,
-		'process_name'    : 'hwmons_barreleye.exe',
+		'process_name'    : 'sensors_hwmon.py',
+		'args'            : [ SYSTEM_NAME ]
 	}
 }
 
@@ -498,4 +499,67 @@
 	return base+offset
 
 
+HWMON_CONFIG = {
+	'0-004a' :  { 
+		'temp1_input' : { 'object_path' : 'temperature/ambient','poll_interval' : 3000,'scale' : 1000,'units' : 'C' },
+	},
+	'6-002d' : {
+		'pwm1' : { 'object_path' : 'speed/fan0','poll_interval' : 10000,'scale' : 1,'units' : '' },
+		'pwm2' : { 'object_path' : 'speed/fan1','poll_interval' : 10000,'scale' : 1,'units' : '' },
+		'pwm3' : { 'object_path' : 'speed/fan2','poll_interval' : 10000,'scale' : 1,'units' : '' },
+	},
+	'6-002e' : {
+		'pwm1' : { 'object_path' : 'speed/fan3','poll_interval' : 10000,'scale' : 1,'units' : '' },
+		'pwm2' : { 'object_path' : 'speed/fan4','poll_interval' : 10000,'scale' : 1,'units' : '' },
+		'pwm3' : { 'object_path' : 'speed/fan5','poll_interval' : 10000,'scale' : 1,'units' : '' },
+	},
+	'3-0050' : {
+		'temp1_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp2_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp3_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp4_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp5_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp6_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp7_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp8_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp9_input' :  { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp10_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp11_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp12_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp13_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp14_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp15_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp16_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp17_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp18_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp19_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp20_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp21_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp22_input' : { 'object_path' : 'temperature/cpu0/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+	},
+	'3-0051' : {
+		'temp1_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp2_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp3_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp4_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp5_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp6_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp7_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp8_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp9_input' :  { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp10_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp11_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp12_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp13_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp14_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp15_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp16_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp17_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp18_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp19_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp20_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp21_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+		'temp22_input' : { 'object_path' : 'temperature/cpu1/<label>','poll_interval' : 1000,'scale' : 1000,'units' : 'C' },
+	},
+}
 
diff --git a/bin/sensors_hwmon.py b/bin/sensors_hwmon.py
new file mode 100755
index 0000000..3574b60
--- /dev/null
+++ b/bin/sensors_hwmon.py
@@ -0,0 +1,196 @@
+#!/usr/bin/python -u
+
+import sys
+import os
+import gobject
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import Openbmc
+if (len(sys.argv) < 2):
+	print "Usage:  sensors_hwmon.py [system name]"
+	exit(1)
+
+System = __import__(sys.argv[1])
+
+DBUS_NAME = 'org.openbmc.sensors.hwmon'
+OBJ_PATH = '/org/openbmc/sensors'
+DIR_POLL_INTERVAL = 10000
+HWMON_PATH = '/sys/class/hwmon'
+
+class SensorValue(Openbmc.DbusProperties):
+	IFACE_NAME = 'org.openbmc.SensorValue'
+	def __init__(self,bus,name):
+		Openbmc.DbusProperties.__init__(self)
+		self.Set(SensorValue.IFACE_NAME,'units',"")
+		dbus.service.Object.__init__(self,bus,name)
+		
+	@dbus.service.method(IFACE_NAME,
+		in_signature='v', out_signature='')
+	def setValue(self,value):
+		changed = False
+		try:
+			old_value = self.Get(SensorValue.IFACE_NAME,'value')
+			if (value != old_value):
+				changed = True
+		except:
+			changed = True
+
+		if (changed == True):
+			self.Set(SensorValue.IFACE_NAME,'value',value)
+			self.Changed(self.getValue(),self.getUnits())
+
+
+
+	@dbus.service.method(IFACE_NAME,
+		in_signature='', out_signature='v')
+	def getValue(self):
+		return self.Get(SensorValue.IFACE_NAME,'value')
+
+	@dbus.service.method(IFACE_NAME,
+		in_signature='', out_signature='s')
+	def getUnits(self):
+		return self.Get(SensorValue.IFACE_NAME,'units')
+
+	@dbus.service.signal(IFACE_NAME,signature='vs')
+	def Changed(self,value,units):
+		pass
+
+def readAttribute(filename):
+	val = ""
+	with open(filename, 'r') as f:
+		for line in f:
+			val = line.rstrip('\n')
+	return val
+
+class HwmonSensor(SensorValue):
+	def __init__(self, bus ,name, attribute ,poll_interval ,units, scale):
+		SensorValue.__init__(self,bus,name)
+		self.attribute = attribute
+		self.scale = 1
+		if scale > 0:
+			self.scale = scale
+		
+		self.Set(SensorValue.IFACE_NAME,'units',units)
+		self.pollSensor()
+
+		if (poll_interval > 0):
+			gobject.timeout_add(poll_interval, self.pollSensor)  
+		else:
+			print "ERROR HWMON: poll_interval must be > 0"
+		self.ObjectAdded(name,SensorValue.IFACE_NAME)
+			
+
+	def pollSensor(self):
+		try:
+			with open(self.attribute, 'r') as f:
+				for line in f:
+					val = int(line.rstrip('\n'))/self.scale
+					SensorValue.setValue(self,val)
+		except:
+			print "Attribute no longer exists: "+self.attribute
+			return False
+
+		return True
+
+	@dbus.service.method(SensorValue.IFACE_NAME,
+		in_signature='v', out_signature='')
+	def setValue(self,value):
+		try:
+			with open(self.attribute, 'w') as f:
+				val = int(value*self.scale)
+				f.write(str(val)+'\n')
+				SensorValue.setValue(self,value)
+		except Exception as e:
+			print e
+			print "Unable to write: "+self.attribute
+		
+		SensorValue.setValue(self,value)
+
+
+
+	
+
+class Sensors(Openbmc.DbusProperties):
+	def __init__(self,bus,name):
+		dbus.service.Object.__init__(self,bus,name)
+		self.sensors = { }
+		self.hwmon_root = { }
+		bus.add_signal_receiver(self.OccActiveHandler, 
+					dbus_interface = "org.openbmc.SensorValue", signal_name = "Changed", 
+					path="/org/openbmc/sensor/virtual/OccStatus" )
+
+		gobject.timeout_add(DIR_POLL_INTERVAL, self.scanDirectory)   
+		self.ObjectAdded(name,DBUS_NAME)
+
+	def OccActiveHandler(self,value,units):
+		print  "OCC "+value
+		if (value == "Enabled"):
+			print "Installing OCC device"
+			os.system("echo occ-i2c 0x50 >  /sys/bus/i2c/devices/i2c-3/new_device")
+			os.system("echo occ-i2c 0x51 >  /sys/bus/i2c/devices/i2c-3/new_device")
+		if (value == "Disabled"):
+			print "Deleting OCC device"
+			os.system("echo 0x50 >  /sys/bus/i2c/devices/i2c-3/delete_device")
+			os.system("echo 0x51 >  /sys/bus/i2c/devices/i2c-3/delete_device")
+
+	def addObject(self,dpath,instance_name,attribute):
+		hwmon = System.HWMON_CONFIG[instance_name][attribute]
+		objsuf = hwmon['object_path']
+		if (objsuf.find('<label>') > -1):
+			label_file = attribute.replace('_input','_label')
+			label = readAttribute(dpath+label_file)
+			objsuf = objsuf.replace('<label>',label)
+
+		objpath = OBJ_PATH+'/'+objsuf
+		spath = dpath+attribute
+		if (self.sensors.has_key(objpath) == False):
+			if os.path.isfile(spath):
+				print "HWMON add: "+objpath+" : "+spath
+				self.sensors[objpath]= HwmonSensor(bus,objpath,spath,
+					hwmon['poll_interval'],hwmon['units'],hwmon['scale'])
+				self.hwmon_root[dpath].append(objpath)
+	
+
+	def scanDirectory(self):
+	 	devices = os.listdir(HWMON_PATH)
+		found_hwmon = {}
+		for d in devices:
+			dpath = HWMON_PATH+'/'+d+'/'
+			found_hwmon[dpath] = True
+			if (self.hwmon_root.has_key(dpath) == False):
+				self.hwmon_root[dpath] = []
+			## the instance name is a soft link
+			instance_name = os.path.realpath(dpath+'device').split('/').pop()
+			if (System.HWMON_CONFIG.has_key(instance_name)):
+	 			for attribute in System.HWMON_CONFIG[instance_name].keys():
+					self.addObject(dpath,instance_name,attribute)
+			else:
+				print "WARNING: Unhandled hwmon: "+dpath
+	
+
+		for k in self.hwmon_root.keys():
+			if (found_hwmon.has_key(k) == False):
+				## need to remove all objects associated with this path
+				print "Removing: "+k
+				for objpath in self.hwmon_root[k]:
+					if (self.sensors.has_key(objpath) == True):
+						print "HWMON remove: "+objpath
+						obj = self.sensors.pop(objpath,None)
+						obj.remove_from_connection()
+				self.hwmon_root.pop(k,None)
+				
+		return True
+
+			
+if __name__ == '__main__':
+	
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+	bus = Openbmc.getDBus()
+	name = dbus.service.BusName(DBUS_NAME,bus)
+	root_sensor = Sensors(bus,OBJ_PATH)
+	mainloop = gobject.MainLoop()
+
+	print "Starting HWMON sensors"
+	mainloop.run()
+