Package Products :: Package ZenModel :: Module TemperatureSensor
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.TemperatureSensor

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  __doc__="""TemperatureSensor 
 12   
 13  TemperatureSensor is an abstraction of a temperature sensor or probe. 
 14   
 15  $Id: TemperatureSensor.py,v 1.7 2004/04/06 22:33:24 edahl Exp $""" 
 16   
 17  __version__ = "$Revision: 1.7 $"[11:-2] 
 18   
 19  from Globals import InitializeClass 
 20   
 21  from Products.ZenRelations.RelSchema import * 
 22   
 23  from HWComponent import HWComponent 
 24   
 25  from Products.ZenModel.ZenossSecurity import * 
 26   
27 -class TemperatureSensor(HWComponent):
28 """TemperatureSensor object""" 29 30 portal_type = meta_type = 'TemperatureSensor' 31 32 state = "unknown" 33 34 _properties = HWComponent._properties + ( 35 {'id':'state', 'type':'string', 'mode':'w'}, 36 ) 37 38 _relations = HWComponent._relations + ( 39 ("hw", ToOne( 40 ToManyCont, "Products.ZenModel.DeviceHW", "temperaturesensors")), 41 ) 42 43 44 factory_type_information = ( 45 { 46 'id' : 'TemperatureSensor', 47 'meta_type' : 'TemperatureSensor', 48 'description' : """Arbitrary device grouping class""", 49 'icon' : 'TemperatureSensor_icon.gif', 50 'product' : 'ZenModel', 51 'factory' : 'manage_addTemperatureSensor', 52 'immediate_view' : 'viewTemperatureSensor', 53 'actions' : 54 ( 55 { 'id' : 'status' 56 , 'name' : 'Status' 57 , 'action' : 'viewTemperatureSensor' 58 , 'permissions' : ('View',) 59 }, 60 { 'id' : 'perfConf' 61 , 'name' : 'Template' 62 , 'action' : 'objTemplates' 63 , 'permissions' : ("Change Device", ) 64 }, 65 ) 66 }, 67 ) 68 69
70 - def temperatureCelsius(self, default=None):
71 """ 72 Return the current temperature in degrees celsius 73 """ 74 tempC = self.cacheRRDValue('temperature_celsius', default) 75 if tempC is None: 76 tempF = self.cacheRRDValue('temperature_fahrenheit', default) 77 if tempF is not None: tempC = (tempF - 32) / 9 * 5 78 if tempC is not None: 79 return long(tempC) 80 return None
81 temperature = temperatureCelsius 82 83
84 - def temperatureFahrenheit(self, default=None):
85 """ 86 Return the current temperature in degrees fahrenheit 87 """ 88 tempC = self.temperatureCelsius(default) 89 if tempC is not None: 90 tempF = tempC * 9 / 5 + 32 91 return long(tempF) 92 return None
93 94
95 - def temperatureCelsiusString(self):
96 """ 97 Return the current temperature in degrees celsius as a string 98 """ 99 tempC = self.temperature() 100 return tempC is None and "unknown" or "%dC" % (tempC,)
101 temperatureString = temperatureCelsiusString 102 103
105 """ 106 Return the current temperature in degrees fahrenheit as a string 107 """ 108 tempF = self.temperatureFahrenheit() 109 return tempF is None and "unknown" or "%dF" % (tempF,)
110 111
112 - def viewName(self):
113 return self.id
114 name = viewName
115 116 InitializeClass(TemperatureSensor) 117