Skip to content

How to unload devices not present anymore in the bus #109

@11ange

Description

@11ange

Hello !
How I can unload ou remove devices that are no present anymore in the bus? Everytime I connect a sensor on the bus a new folder is created (at /sys/bus/w1/devices/w1_bus_master1 with the HW-ID of the new sensor), but folders for defective sensors or sensors not present are still there.

Here is part of my code:

sensores = W1ThermSensor.get_available_sensors()
if len(sensores) == 2:
    try:
        sensor1 = W1ThermSensor(Sensor.DS18B20, sensores[0].id)
        dicio_ds["ds0"] = format(sensor1.get_temperature(), "^4.1f")
    except SensorNotReadyError:
        dicio_ds["ds0"] = -126
    try:
        sensor2 = W1ThermSensor(Sensor.DS18B20, sensores[1].id)
        dicio_ds["ds1"] = format(sensor2.get_temperature(), "^4.1f")
    except SensorNotReadyError:
        dicio_ds["ds1"] = -126
else:
    dicio_ds["ds0"] = -126
    dicio_ds["ds1"] = -126

If one of the sensors are defective and I remove it and put a new one, the len(sensores)=3 and it is not desirable, as I have only 2 sensors operational.
Is this possible or should I improve my code?
Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions