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