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

# Source Code for Module Products.ZenModel.TemperatureSensor

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, Zenoss Inc.
      5  #
      6  # This program is free software; you can redistribute it and/or modify it
      7  # under the terms of the GNU General Public License version 2 or (at your
      8  # option) any later version as published by the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     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
     30 -class TemperatureSensor(HWComponent):
     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
     73 -    def temperatureCelsius(self, default=None):
     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
     87 -    def temperatureFahrenheit(self, default=None):
     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
     98 -    def temperatureCelsiusString(self):
     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
    107 -    def temperatureFahrenheitString(self):
    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
    115 -    def viewName(self):
    116          return self.id
    117      name = viewName
    118
    119  InitializeClass(TemperatureSensor)
    120