1
2
3
4
5
6
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
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
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
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
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
114 name = viewName
115
116 InitializeClass(TemperatureSensor)
117