xref: /openbmc/dbus-sensors/src/hwmon-temp/HwmonTempMain.cpp (revision 964057d1a69640a3f3bb7afbf2de9e6c98dc7cff)
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #include "DeviceMgmt.hpp"
18 #include "HwmonTempSensor.hpp"
19 #include "SensorPaths.hpp"
20 #include "Thresholds.hpp"
21 #include "Utils.hpp"
22 
23 #include <boost/asio/error.hpp>
24 #include <boost/asio/io_context.hpp>
25 #include <boost/asio/post.hpp>
26 #include <boost/asio/steady_timer.hpp>
27 #include <boost/container/flat_map.hpp>
28 #include <boost/container/flat_set.hpp>
29 #include <phosphor-logging/lg2.hpp>
30 #include <phosphor-logging/lg2/flags.hpp>
31 #include <sdbusplus/asio/connection.hpp>
32 #include <sdbusplus/asio/object_server.hpp>
33 #include <sdbusplus/bus.hpp>
34 #include <sdbusplus/bus/match.hpp>
35 #include <sdbusplus/message.hpp>
36 #include <sdbusplus/message/native_types.hpp>
37 
38 #include <algorithm>
39 #include <array>
40 #include <chrono>
41 #include <cstddef>
42 #include <cstdint>
43 #include <filesystem>
44 #include <functional>
45 #include <memory>
46 #include <optional>
47 #include <regex>
48 #include <string>
49 #include <system_error>
50 #include <utility>
51 #include <variant>
52 #include <vector>
53 
54 static constexpr float pollRateDefault = 0.5;
55 
56 static constexpr double maxValuePressure = 120000;      // Pascals
57 static constexpr double minValuePressure = 30000;       // Pascals
58 
59 static constexpr double maxValueRelativeHumidity = 100; // PercentRH
60 static constexpr double minValueRelativeHumidity = 0;   // PercentRH
61 
62 static constexpr double maxValueTemperature = 127;      // DegreesC
63 static constexpr double minValueTemperature = -128;     // DegreesC
64 
65 static const I2CDeviceTypeMap sensorTypes{
66     {"ADM1021", I2CDeviceType{"adm1021", true}},
67     {"BME280", I2CDeviceType{"bme280", false}},
68     {"DPS310", I2CDeviceType{"dps310", false}},
69     {"EMC1403", I2CDeviceType{"emc1403", true}},
70     {"EMC1412", I2CDeviceType{"emc1412", true}},
71     {"EMC1413", I2CDeviceType{"emc1413", true}},
72     {"EMC1414", I2CDeviceType{"emc1414", true}},
73     {"G751", I2CDeviceType{"g751", true}},
74     {"HDC1080", I2CDeviceType{"hdc1080", false}},
75     {"JC42", I2CDeviceType{"jc42", true}},
76     {"LM75A", I2CDeviceType{"lm75a", true}},
77     {"LM95234", I2CDeviceType{"lm95234", true}},
78     {"MAX31725", I2CDeviceType{"max31725", true}},
79     {"MAX31730", I2CDeviceType{"max31730", true}},
80     {"MAX6581", I2CDeviceType{"max6581", true}},
81     {"MAX6654", I2CDeviceType{"max6654", true}},
82     {"MAX6639", I2CDeviceType{"max6639", true}},
83     {"MCP9600", I2CDeviceType{"mcp9600", false}},
84     {"NCT6779", I2CDeviceType{"nct6779", true}},
85     {"NCT7802", I2CDeviceType{"nct7802", true}},
86     {"PT5161L", I2CDeviceType{"pt5161l", true}},
87     {"SBTSI", I2CDeviceType{"sbtsi", true}},
88     {"SI7020", I2CDeviceType{"si7020", false}},
89     {"TMP100", I2CDeviceType{"tmp100", true}},
90     {"TMP1075", I2CDeviceType{"tmp1075", true}},
91     {"TMP112", I2CDeviceType{"tmp112", true}},
92     {"TMP175", I2CDeviceType{"tmp175", true}},
93     {"TMP411", I2CDeviceType{"tmp411", true}},
94     {"TMP421", I2CDeviceType{"tmp421", true}},
95     {"TMP432", I2CDeviceType{"tmp432", true}},
96     {"TMP441", I2CDeviceType{"tmp441", true}},
97     {"TMP451", I2CDeviceType{"tmp451", true}},
98     {"TMP461", I2CDeviceType{"tmp461", true}},
99     {"TMP464", I2CDeviceType{"tmp464", true}},
100     {"TMP468", I2CDeviceType{"tmp468", true}},
101     {"TMP75", I2CDeviceType{"tmp75", true}},
102     {"W83773G", I2CDeviceType{"w83773g", true}},
103 };
104 
getSensorParameters(const std::filesystem::path & path)105 static struct SensorParams getSensorParameters(
106     const std::filesystem::path& path)
107 {
108     // offset is to default to 0 and scale to 1, see lore
109     // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
110     struct SensorParams tmpSensorParameters = {
111         .minValue = minValueTemperature,
112         .maxValue = maxValueTemperature,
113         .offsetValue = 0.0,
114         .scaleValue = 1.0,
115         .units = sensor_paths::unitDegreesC,
116         .typeName = "temperature"};
117 
118     // For IIO RAW sensors we get a raw_value, an offset, and scale
119     // to compute the value = (raw_value + offset) * scale
120     // with a _raw IIO device we need to get the
121     // offsetValue and scaleValue from the driver
122     // these are used to compute the reading in
123     // units that have yet to be scaled for D-Bus.
124     const std::string pathStr = path.string();
125     if (pathStr.ends_with("_raw"))
126     {
127         std::string pathOffsetStr =
128             pathStr.substr(0, pathStr.size() - 4) + "_offset";
129         std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
130         // In case there is nothing to read skip this device
131         // This is not an error condition see lore
132         // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
133         if (tmpOffsetValue)
134         {
135             tmpSensorParameters.offsetValue = *tmpOffsetValue;
136         }
137 
138         std::string pathScaleStr =
139             pathStr.substr(0, pathStr.size() - 4) + "_scale";
140         std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
141         // In case there is nothing to read skip this device
142         // This is not an error condition see lore
143         // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
144         if (tmpScaleValue)
145         {
146             tmpSensorParameters.scaleValue = *tmpScaleValue;
147         }
148     }
149 
150     // Temperatures are read in milli degrees Celsius, we need
151     // degrees Celsius. Pressures are read in kilopascal, we need
152     // Pascals.  On D-Bus for Open BMC we use the International
153     // System of Units without prefixes. Links to the kernel
154     // documentation:
155     // https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
156     // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
157     if (path.filename() == "in_pressure_input" ||
158         path.filename() == "in_pressure_raw")
159     {
160         tmpSensorParameters.minValue = minValuePressure;
161         tmpSensorParameters.maxValue = maxValuePressure;
162         // Pressures are read in kilopascal, we need Pascals.
163         tmpSensorParameters.scaleValue *= 1000.0;
164         tmpSensorParameters.typeName = "pressure";
165         tmpSensorParameters.units = sensor_paths::unitPascals;
166     }
167     else if (path.filename() == "in_humidityrelative_input" ||
168              path.filename() == "in_humidityrelative_raw")
169     {
170         tmpSensorParameters.minValue = minValueRelativeHumidity;
171         tmpSensorParameters.maxValue = maxValueRelativeHumidity;
172         // Relative Humidity are read in milli-percent, we need percent.
173         tmpSensorParameters.scaleValue *= 0.001;
174         tmpSensorParameters.typeName = "humidity";
175         tmpSensorParameters.units = sensor_paths::unitPercentRH;
176     }
177     else
178     {
179         // Temperatures are read in milli degrees Celsius,
180         // we need degrees Celsius.
181         tmpSensorParameters.scaleValue *= 0.001;
182     }
183 
184     return tmpSensorParameters;
185 }
186 
187 struct SensorConfigKey
188 {
189     uint64_t bus;
190     uint64_t addr;
operator <SensorConfigKey191     bool operator<(const SensorConfigKey& other) const
192     {
193         if (bus != other.bus)
194         {
195             return bus < other.bus;
196         }
197         return addr < other.addr;
198     }
199 };
200 
201 struct SensorConfig
202 {
203     std::string sensorPath;
204     SensorData sensorData;
205     std::string interface;
206     SensorBaseConfigMap config;
207     std::vector<std::string> name;
208 };
209 
210 using SensorConfigMap =
211     boost::container::flat_map<SensorConfigKey, SensorConfig>;
212 
buildSensorConfigMap(const ManagedObjectType & sensorConfigs)213 static SensorConfigMap buildSensorConfigMap(
214     const ManagedObjectType& sensorConfigs)
215 {
216     SensorConfigMap configMap;
217     for (const auto& [path, cfgData] : sensorConfigs)
218     {
219         for (const auto& [intf, cfg] : cfgData)
220         {
221             auto busCfg = cfg.find("Bus");
222             auto addrCfg = cfg.find("Address");
223             if ((busCfg == cfg.end()) || (addrCfg == cfg.end()))
224             {
225                 continue;
226             }
227 
228             if ((std::get_if<uint64_t>(&busCfg->second) == nullptr) ||
229                 (std::get_if<uint64_t>(&addrCfg->second) == nullptr))
230             {
231                 lg2::error("'{PATH}' Bus or Address invalid", "PATH", path.str);
232                 continue;
233             }
234 
235             std::vector<std::string> hwmonNames;
236             auto nameCfg = cfg.find("Name");
237             if (nameCfg != cfg.end())
238             {
239                 hwmonNames.push_back(std::get<std::string>(nameCfg->second));
240                 size_t i = 1;
241                 while (true)
242                 {
243                     auto sensorNameCfg = cfg.find("Name" + std::to_string(i));
244                     if (sensorNameCfg == cfg.end())
245                     {
246                         break;
247                     }
248                     hwmonNames.push_back(
249                         std::get<std::string>(sensorNameCfg->second));
250                     i++;
251                 }
252             }
253 
254             SensorConfigKey key = {std::get<uint64_t>(busCfg->second),
255                                    std::get<uint64_t>(addrCfg->second)};
256             SensorConfig val = {path.str, cfgData, intf, cfg, hwmonNames};
257 
258             auto [it, inserted] = configMap.emplace(key, std::move(val));
259             if (!inserted)
260             {
261                 lg2::error(
262                     "'{PATH}': ignoring duplicate entry for '{BUS}', '{ADDR}'",
263                     "PATH", path.str, "BUS", key.bus, "ADDR", lg2::hex,
264                     key.addr);
265             }
266         }
267     }
268     return configMap;
269 }
270 
createSensors(boost::asio::io_context & io,sdbusplus::asio::object_server & objectServer,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors,std::shared_ptr<sdbusplus::asio::connection> & dbusConnection,const std::shared_ptr<boost::container::flat_set<std::string>> & sensorsChanged,bool activateOnly)271 void createSensors(
272     boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
273     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
274         sensors,
275     std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
276     const std::shared_ptr<boost::container::flat_set<std::string>>&
277         sensorsChanged,
278     bool activateOnly)
279 {
280     auto getter = std::make_shared<GetSensorConfiguration>(
281         dbusConnection,
282         [&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
283          activateOnly](const ManagedObjectType& sensorConfigurations) {
284             bool firstScan = sensorsChanged == nullptr;
285 
286             SensorConfigMap configMap =
287                 buildSensorConfigMap(sensorConfigurations);
288 
289             auto devices =
290                 instantiateDevices(sensorConfigurations, sensors, sensorTypes);
291 
292             // IIO _raw devices look like this on sysfs:
293             //     /sys/bus/iio/devices/iio:device0/in_temp_raw
294             //     /sys/bus/iio/devices/iio:device0/in_temp_offset
295             //     /sys/bus/iio/devices/iio:device0/in_temp_scale
296             //
297             // Other IIO devices look like this on sysfs:
298             //     /sys/bus/iio/devices/iio:device1/in_temp_input
299             //     /sys/bus/iio/devices/iio:device1/in_pressure_input
300             std::vector<std::filesystem::path> paths;
301             std::filesystem::path root("/sys/bus/iio/devices");
302             findFiles(root, R"(in_temp\d*_(input|raw))", paths);
303             findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
304             findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
305             findFiles(std::filesystem::path("/sys/class/hwmon"),
306                       R"(temp\d+_input)", paths);
307 
308             // iterate through all found temp and pressure sensors,
309             // and try to match them with configuration
310             for (auto& path : paths)
311             {
312                 std::smatch match;
313                 const std::string pathStr = path.string();
314                 auto directory = path.parent_path();
315                 std::filesystem::path device;
316 
317                 std::string deviceName;
318                 std::error_code ec;
319                 if (pathStr.starts_with("/sys/bus/iio/devices"))
320                 {
321                     device = std::filesystem::canonical(directory, ec);
322                     if (ec)
323                     {
324                         lg2::error("Fail to find device in '{PATH}'", "PATH",
325                                    pathStr);
326                         continue;
327                     }
328                     deviceName = device.parent_path().stem();
329                 }
330                 else
331                 {
332                     device =
333                         std::filesystem::canonical(directory / "device", ec);
334                     if (ec)
335                     {
336                         lg2::error("Fail to find device in '{PATH}'", "PATH",
337                                    pathStr);
338                         continue;
339                     }
340                     deviceName = device.stem();
341                 }
342 
343                 uint64_t bus = 0;
344                 uint64_t addr = 0;
345                 if (!getDeviceBusAddr(deviceName, bus, addr))
346                 {
347                     continue;
348                 }
349 
350                 auto thisSensorParameters = getSensorParameters(path);
351                 auto findSensorCfg = configMap.find({bus, addr});
352                 if (findSensorCfg == configMap.end())
353                 {
354                     continue;
355                 }
356 
357                 const std::string& interfacePath =
358                     findSensorCfg->second.sensorPath;
359                 auto findI2CDev = devices.find(interfacePath);
360 
361                 std::shared_ptr<I2CDevice> i2cDev;
362                 if (findI2CDev != devices.end())
363                 {
364                     // If we're only looking to activate newly-instantiated i2c
365                     // devices and this sensor's underlying device was already
366                     // there before this call, there's nothing more to do here.
367                     if (activateOnly && !findI2CDev->second.second)
368                     {
369                         continue;
370                     }
371                     i2cDev = findI2CDev->second.first;
372                 }
373 
374                 const SensorData& sensorData = findSensorCfg->second.sensorData;
375                 std::string sensorType = findSensorCfg->second.interface;
376                 auto pos = sensorType.find_last_of('.');
377                 if (pos != std::string::npos)
378                 {
379                     sensorType = sensorType.substr(pos + 1);
380                 }
381                 const SensorBaseConfigMap& baseConfigMap =
382                     findSensorCfg->second.config;
383                 std::vector<std::string>& hwmonName =
384                     findSensorCfg->second.name;
385 
386                 // Temperature has "Name", pressure has "Name1"
387                 auto findSensorName = baseConfigMap.find("Name");
388                 int index = 1;
389                 if (thisSensorParameters.typeName == "pressure")
390                 {
391                     findSensorName = baseConfigMap.find("NamePressure");
392                     index = 2;
393                 }
394                 if (thisSensorParameters.typeName == "humidity")
395                 {
396                     findSensorName = baseConfigMap.find("NameHumidity");
397                     index = 3;
398                 }
399 
400                 if (findSensorName == baseConfigMap.end())
401                 {
402                     lg2::error(
403                         "could not determine configuration name for '{NAME}'",
404                         "NAME", deviceName);
405                     continue;
406                 }
407                 std::string sensorName =
408                     std::get<std::string>(findSensorName->second);
409                 // on rescans, only update sensors we were signaled by
410                 auto findSensor = sensors.find(sensorName);
411                 if (!firstScan && findSensor != sensors.end())
412                 {
413                     bool found = false;
414                     auto it = sensorsChanged->begin();
415                     while (it != sensorsChanged->end())
416                     {
417                         if (it->ends_with(findSensor->second->name))
418                         {
419                             it = sensorsChanged->erase(it);
420                             findSensor->second = nullptr;
421                             found = true;
422                             break;
423                         }
424                         ++it;
425                     }
426                     if (!found)
427                     {
428                         continue;
429                     }
430                 }
431 
432                 std::vector<thresholds::Threshold> sensorThresholds;
433 
434                 if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
435                                                nullptr, &index))
436                 {
437                     lg2::error("error populating thresholds for "
438                                "'{NAME}', index: '{INDEX}'",
439                                "NAME", sensorName, "INDEX", index);
440                 }
441 
442                 float pollRate = getPollRate(baseConfigMap, pollRateDefault);
443                 PowerState readState = getPowerState(baseConfigMap);
444 
445                 auto permitSet = getPermitSet(baseConfigMap);
446                 auto& sensor = sensors[sensorName];
447                 if (!activateOnly)
448                 {
449                     sensor = nullptr;
450                 }
451                 auto hwmonFile = getFullHwmonFilePath(directory.string(),
452                                                       "temp1", permitSet);
453                 if (pathStr.starts_with("/sys/bus/iio/devices"))
454                 {
455                     hwmonFile = pathStr;
456                 }
457                 if (hwmonFile)
458                 {
459                     if (sensor != nullptr)
460                     {
461                         sensor->activate(*hwmonFile, i2cDev);
462                     }
463                     else
464                     {
465                         sensor = std::make_shared<HwmonTempSensor>(
466                             *hwmonFile, sensorType, objectServer,
467                             dbusConnection, io, sensorName,
468                             std::move(sensorThresholds), thisSensorParameters,
469                             pollRate, interfacePath, readState, i2cDev);
470                         sensor->setupRead();
471                     }
472                 }
473                 hwmonName.erase(
474                     remove(hwmonName.begin(), hwmonName.end(), sensorName),
475                     hwmonName.end());
476 
477                 // Looking for keys like "Name1" for temp2_input,
478                 // "Name2" for temp3_input, etc.
479                 int i = 0;
480                 while (true)
481                 {
482                     ++i;
483                     auto findKey =
484                         baseConfigMap.find("Name" + std::to_string(i));
485                     if (findKey == baseConfigMap.end())
486                     {
487                         break;
488                     }
489                     std::string sensorName =
490                         std::get<std::string>(findKey->second);
491                     hwmonFile = getFullHwmonFilePath(
492                         directory.string(), "temp" + std::to_string(i + 1),
493                         permitSet);
494                     if (pathStr.starts_with("/sys/bus/iio/devices"))
495                     {
496                         continue;
497                     }
498                     if (hwmonFile)
499                     {
500                         // To look up thresholds for these additional sensors,
501                         // match on the Index property in the threshold data
502                         // where the index comes from the sysfs file we're on,
503                         // i.e. index = 2 for temp2_input.
504                         int index = i + 1;
505                         std::vector<thresholds::Threshold> thresholds;
506 
507                         if (!parseThresholdsFromConfig(sensorData, thresholds,
508                                                        nullptr, &index))
509                         {
510                             lg2::error("error populating thresholds for "
511                                        "'{NAME}', index: '{INDEX}'",
512                                        "NAME", sensorName, "INDEX", index);
513                         }
514 
515                         auto& sensor = sensors[sensorName];
516                         if (!activateOnly)
517                         {
518                             sensor = nullptr;
519                         }
520 
521                         if (sensor != nullptr)
522                         {
523                             sensor->activate(*hwmonFile, i2cDev);
524                         }
525                         else
526                         {
527                             sensor = std::make_shared<HwmonTempSensor>(
528                                 *hwmonFile, sensorType, objectServer,
529                                 dbusConnection, io, sensorName,
530                                 std::move(thresholds), thisSensorParameters,
531                                 pollRate, interfacePath, readState, i2cDev);
532                             sensor->setupRead();
533                         }
534                     }
535 
536                     hwmonName.erase(
537                         remove(hwmonName.begin(), hwmonName.end(), sensorName),
538                         hwmonName.end());
539                 }
540                 if (hwmonName.empty())
541                 {
542                     configMap.erase(findSensorCfg);
543                 }
544             }
545         });
546     std::vector<std::string> types;
547     types.reserve(sensorTypes.size());
548     for (const auto& [type, dt] : sensorTypes)
549     {
550         types.push_back(type);
551     }
552     getter->getConfiguration(types);
553 }
554 
interfaceRemoved(sdbusplus::message_t & message,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors)555 void interfaceRemoved(
556     sdbusplus::message_t& message,
557     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
558         sensors)
559 {
560     sdbusplus::message::object_path path;
561     std::vector<std::string> interfaces;
562 
563     message.read(path, interfaces);
564 
565     // If the xyz.openbmc_project.Confguration.X interface was removed
566     // for one or more sensors, delete those sensor objects.
567     auto sensorIt = sensors.begin();
568     while (sensorIt != sensors.end())
569     {
570         if (sensorIt->second && (sensorIt->second->configurationPath == path) &&
571             (std::find(interfaces.begin(), interfaces.end(),
572                        sensorIt->second->configInterface) != interfaces.end()))
573         {
574             sensorIt = sensors.erase(sensorIt);
575         }
576         else
577         {
578             sensorIt++;
579         }
580     }
581 }
582 
powerStateChanged(PowerState type,bool newState,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors,boost::asio::io_context & io,sdbusplus::asio::object_server & objectServer,std::shared_ptr<sdbusplus::asio::connection> & dbusConnection)583 static void powerStateChanged(
584     PowerState type, bool newState,
585     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
586         sensors,
587     boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
588     std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
589 {
590     if (newState)
591     {
592         createSensors(io, objectServer, sensors, dbusConnection, nullptr, true);
593     }
594     else
595     {
596         for (auto& [path, sensor] : sensors)
597         {
598             if (sensor != nullptr && sensor->readState == type)
599             {
600                 sensor->deactivate();
601             }
602         }
603     }
604 }
605 
main()606 int main()
607 {
608     boost::asio::io_context io;
609     auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
610     sdbusplus::asio::object_server objectServer(systemBus, true);
611     objectServer.add_manager("/xyz/openbmc_project/sensors");
612     systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
613 
614     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
615         sensors;
616     auto sensorsChanged =
617         std::make_shared<boost::container::flat_set<std::string>>();
618 
619     auto powerCallBack = [&sensors, &io, &objectServer,
620                           &systemBus](PowerState type, bool state) {
621         powerStateChanged(type, state, sensors, io, objectServer, systemBus);
622     };
623     setupPowerMatchCallback(systemBus, powerCallBack);
624 
625     boost::asio::post(io, [&]() {
626         createSensors(io, objectServer, sensors, systemBus, nullptr, false);
627     });
628 
629     boost::asio::steady_timer filterTimer(io);
630     std::function<void(sdbusplus::message_t&)> eventHandler =
631         [&](sdbusplus::message_t& message) {
632             sensorsChanged->insert(message.get_path());
633             // this implicitly cancels the timer
634             filterTimer.expires_after(std::chrono::seconds(1));
635 
636             filterTimer.async_wait([&](const boost::system::error_code& ec) {
637                 if (ec == boost::asio::error::operation_aborted)
638                 {
639                     /* we were canceled*/
640                     return;
641                 }
642                 if (ec)
643                 {
644                     lg2::error("timer error");
645                     return;
646                 }
647                 createSensors(io, objectServer, sensors, systemBus,
648                               sensorsChanged, false);
649             });
650         };
651 
652     std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
653         setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
654     setupManufacturingModeMatch(*systemBus);
655 
656     // Watch for entity-manager to remove configuration interfaces
657     // so the corresponding sensors can be removed.
658     auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match_t>(
659         static_cast<sdbusplus::bus_t&>(*systemBus),
660         "type='signal',member='InterfacesRemoved',arg0path='" +
661             std::string(inventoryPath) + "/'",
662         [&sensors](sdbusplus::message_t& msg) {
663             interfaceRemoved(msg, sensors);
664         });
665 
666     matches.emplace_back(std::move(ifaceRemovedMatch));
667 
668     io.run();
669 }
670