Checks if an instance of the requested sensor already exists for the desired port. If it does, return that one If there's nothing on that port, or there's another sensor, then create the requested sensor and return this new one
(port, sensor_class)
| 238 | ################################################################## |
| 239 | |
| 240 | def get_sensor_instance(port, sensor_class): |
| 241 | ''' |
| 242 | Checks if an instance of the requested sensor already exists for |
| 243 | the desired port. If it does, return that one |
| 244 | If there's nothing on that port, or there's another sensor, |
| 245 | then create the requested sensor and return this new one |
| 246 | ''' |
| 247 | try: |
| 248 | if known_sensors[port] == None or \ |
| 249 | isinstance(known_sensors[port], sensor_class) is False: |
| 250 | try: |
| 251 | known_sensors[port] = sensor_class(port, gpg) |
| 252 | except Exception as e: |
| 253 | print("get_sensor_instance {}".format(e)) |
| 254 | known_sensors[port] = None |
| 255 | except Exception as e: |
| 256 | print("get_sensor_instance 2 {}".format(e)) |
| 257 | known_sensors[port] = None |
| 258 | |
| 259 | # print(known_sensors[port]) |
| 260 | return(known_sensors[port]) |
| 261 | |
| 262 | |
| 263 | def set_regex_string(): |
no outgoing calls
no test coverage detected