'Scan I2C-HATs digital inputs and fire callbacks.'

def scan(self, i2c_hat):

    if hasattr(i2c_hat, self._DIGITAL_INPUTS):
        digital_inputs = getattr(i2c_hat, self._DIGITAL_INPUTS)
        callbacks = getattr(digital_inputs, self._CALLBACKS)
        old_value = getattr(digital_inputs, self._OLD_VALUE)
        value = digital_inputs.value
        if ((old_value is not None) and (value != old_value)):
            for channel in range(0, len(digital_inputs.channels)):
                state = ((value >> channel) & 1)
                old_state = ((old_value >> channel) & 1)
                if (state != old_state):
                    callback = callbacks.get(channel, None)
                    if (callback is not None):
                        callback(state)
        setattr(digital_inputs, self._OLD_VALUE, value)
