From acd193ce6b6ce1bb5d552c5e094c4e98dcb5d03b Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Thu, 15 Jan 2015 12:53:55 -0500 Subject: [PATCH] Allow request for single sensor by name In some cases, it is useful for management software to specifically read one or a few sensors specifically. This new function allows management software a convenient way to get sensors without requesting a full sweep. Change-Id: Ibbb7ab0d76b7aea934be804c6ee79c34f6a6c568 --- pyghmi/ipmi/command.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 8eff43fe..e90d7463 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -348,6 +348,26 @@ class Command(object): summary['badreadings'].append(reading) return summary + def get_sensor_reading(self, sensorname): + """Get a sensor reading by name + + Returns a single decoded sensor reading per the name + passed in + + :param sensorname: Name of the desired sensor + :returns: sdr.SensorReading object + """ + if self._sdr is None: + self._sdr = sdr.SDR(self) + for sensor in self._sdr.get_sensor_numbers(): + if self._sdr.sensors[sensor].name == sensorname: + rsp = self.raw_command(command=0x2d, netfn=4, data=(sensor,)) + if 'error' in rsp: + raise Exception(rsp['error']) + return self._sdr.sensors[sensor].decode_sensor_reading( + rsp['data']) + raise Exception('Sensor not found: ' + sensorname) + def get_sensor_data(self): """Get sensor reading objects